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.