Step 1: In androidmanifest. add the following two pieces of code to XML: [Java] view plaincopy <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "com. PCCW "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 8 "/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <activity Android: Name = ". mainactivity "Android: Label =" @ string/app_name "> <intent-filter> <Ction Android: Name = "android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity> <! -Add code 1 --> <uses-library Android: Name = "android. Test. Runner"/> </Application> <! -Add code 2 --> <instrumentation Android: Name = "android. test. instrumentationtestrunner "Android: targetpackage =" com. PCCW "Android: Label =" AAA "/> </manifest> 1. <uses-library Android: Name = "android. test. runner "/> indicates introducing some dependent libraries in the unit test framework. 2. <instrumentation Android: Name = "android. test. instrumentationtestrunner "Android: targetpackage =" com. PCCW "Android: Label =" AAA "/> indicates the Startup Device for configuring the unit test framework. There are several types of start devices. You can choose from them. Generally, we use the above. 3. the targetpackage is the same as the preceding package, indicating that the unit test framework and the current application are in the same process. Step 2: Compile the business logic, that is, the module to be tested [Java] view plaincopypublic class personservice {public void save (string name) {string sub = Name. substring (6) ;}public int add (int A, int B) {return a + B ;}} Step 3: write the unit test code [Java] view plaincopypublic class personservicetest extends androidtestcase {public void testsave () throws exception {personservice service = new personservice (); service. save (null);} public void testadd () throws exception {personservice service = new personservice (); int result = service. add (1, 2); assert. assertequals (3, result) ;}} Step 4: Open the outline window in eclipse, where all methods of the unit test class are displayed and the method to be tested, right-click the test method, select Run as, and then select Android JUnit test. If an exception or error occurs, the following situation occurs, it will be as follows: