Unit Test of cainiao learning android

Source: Internet
Author: User

In the android project, you only need to perform the unit test in the following three aspects:

1. Configure the following in the project list file:

<? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "net. hnspi. test "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 8 "/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <! -- Use the Test Library --> <uses-library Android: Name = "android. test. runner "/> <activity Android: Name = ". mainactivity "Android: Label =" @ string/app_name "> <intent-filter> <action Android: Name =" android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity> </Application> <! -- Android: targetpackage = "net. hnspi. test "is the package name of the project --> <instrumentation Android: Name =" android. test. instrumentationtestrunner "Android: targetpackage =" net. hnspi. test "Android: Label =" tests for my app "/> </manifest>


2. The test class inherits the Android. Test. androidtestcase class.

 package net. hnspi. test; import JUnit. framework. assert; import net. hnspi. service. personservice; import android. test. androidtestcase; public class personservicetest extends androidtestcase {public void testsave () throws exception {personservice PS = new personservice (); int T = ps. save (); assert. assertequals (21, T); // test return value }}

3. Run the test.

   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.