Add two items to the Androidmanifest.xml file, respectively:
1, Uses-library, located in the application inside.
2, instrumentation, and application peers.
The complete Androidmanifest.xml file is as follows:
1<?xml version= "1.0" encoding= "Utf-8"?>2<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"3 Package= "Com.lzb.study.db"4Android:versioncode= "1"5Android:versionname= "1.0" >6<application android:icon= "@drawable/icon" android:label= "@string/app_name" >7<!--unit Test--8<uses-library android:name= "Android.test.runner"/>9<activity android:name= ". Dbactivity "TenAndroid:label= "@string/app_name" > One<intent-filter> A<action android:name= "Android.intent.action.MAIN"/> -<category android:name= "Android.intent.category.LAUNCHER"/> -</intent-filter> the</activity> - -</application> - +<!--start the tester-- -<instrumentation android:name= "Android.test.InstrumentationTestRunner" +Android:targetpackage= "com.lzb.study.db" Android:label = "Tests for My App"/> A at</manifest>
Then, build the test class. The test method in the test class must begin with testing.
1 Public classPersonservicetestextendsAndroidtestcase {2 3 Public voidTestsave ()throwsException {4Personservice PS =NewPersonservice ( This. GetContext ());5Person person =NewPerson ();6Person.setname ("Li Gang");7Person.setage (( Short) 0);8 Ps.save (person);9 Ten } One}
Then, in the Test class, select TestCase, right-click, select Run as--and Android Junit Test to start the case.
Android builds JUnit test environment