1,Android test code when the first need to declare services in the manifest, mainly including the copy of 2 tags: such as the red part of the code,
The instrumentation label needs to be application, while the uses-library and activity are lateral.
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example.datebase "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/>"<instrumentation android:label= "Tests for MyApp" Android:name= "Android.test.InstrumentationTestRunner "Android:targetpackage=" Com.example.datebase "/><application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@strin G/app_name "Android:theme=" @style/apptheme "><uses-library android:name= "Android.test.runner"/><activity android:name= "com.example.datebase.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& Gt </application></manifest>
2, create a test class, it inherits Androidtestcase, and in the test function function can not pass parameters, the following testadd cannot pass the argument, the negation will not execute this test function
public class Persontest extends Androidtestcase {public void Testadd () throws Exception {System.out.println ("start"); Persondao db2=new Persondao (GetContext ());d B2.add ("Zhangpeng", 156,12); SYSTEM.OUT.PRINTLN ("Success");}}
Android Code functional test