1. modify the configuration file androidmanifest. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "cn. ycmoon. Test. Activity" Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Uses-SDK Android: minsdkversion = "8"/>
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<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>
<Instrumentation Android: Name = "android. Test. instrumentationtestrunner"
Android: targetpackage = "cn. ycmoon. Test. Activity" Android: Label = "testing"/>
</Manifest>
Note: 1. Add it before the activity in the application Node<Uses-library Android: Name = "android. Test. Runner"/>
2. Add an application Node<Instrumentation Android: Name = "android. Test. instrumentationtestrunner" Android: targetpackage = "cn. ycmoon. Test. Activity" Android: Label = "testing"/>
2. Compile the method in the corresponding package,
3. Add a test folder [customizable] To the src directory at the same level, and create the same package name as the project: CN. ycmoon. Test. activity.
4. Right-click the unit test method and choose new> JUnit test case. The following page is displayed:
Select superclass as follows:
Click Next and select the method to be tested:
Click Finish.
Add the new unit test class to the test/project package name.
Add an implementation in the Unit Test method:
Expand the unit test class under test/CN. ycmoon. Test. Activity, right-click the method to be tested, and choose run as> Android JUnit test. The unit test result page is displayed.
If there is no error in this method, the result will display a green status bar: