Original address: http://blog.csdn.net/duancanmeng/article/details/7458851
The first step: Add the following two code to the Androidmanifest.xml:
<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> <action android:name= "Android.intent.action.MAI N "/> <category android:name=" Android.intent.category.LAUNCHER "/> </INTENT-FILTER&G T </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"/> representative to bring in some of the dependent libraries in the Unit testing framework
2. <instrumentation android:name= "Android.test.InstrumentationTestRunner" android:targetpackage= "COM.PCCW" Android Oid:label= "AAA"/> Represents the start-up unit of the Configuration Unit test framework, there are several classes of start-up devices, you can choose, generally we use the above.
3. Targetpackage is the same as the package above, which represents the unit test framework and the current application is in the same process
Step Two: Write the business logic, the module that needs to be tested
Public class Personservice { publicvoid Save (String name) { = name.substring (6); } Public int Add (intint b) { return a +B; }}
Step three: Write the unit test code
Public classPersonservicetestextendsAndroidtestcase { Public voidTestsave ()throwsException {personservice service=NewPersonservice (); Service.save (NULL); } Public voidTestadd ()throwsException {personservice service=NewPersonservice (); intresult = Service.add (1, 2); Assert.assertequals (3, result); }}
Android Learning Note: Unit Testing for Android apps