----------------新建DemoDao.java--------------
package com.neter.test.dao; import android.util.Log; public class DemoDao { public void save (){ Log.i ( "DemoDao" , "用来测试的方法" ) ; } }
----------------新建DemoDaoTest.java--------------
package com.neter.test.dao; import android.test.AndroidTestCase; import android.util.Log; public class DemoDaoTest extends AndroidTestCase { public void testSave () { new DemoDao () .save () ; Log.i ( "DemoDaoTest" , "测试" ) ; } }
-------------------------------AndroidManifest.xml--------------------------
<?xml version="1.0" encoding= "utf-8" ?> <manifest xmlns:android= "http://schemas.android.com/apk/res/android" package = "com.neter.test.dao" android:versionCode= "1" android:versionName= "1.0" > <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.InstrumentationTestRunne r" android:targetPackage= "com.neter.test.dao" android:label= "Testing" ></instrumentation> </manifest>
上面配置文件中
MainActivity为android程序入口,请自已新建代码略
<uses-library android:name="android.test.runner" />不可修改
android:name= "android.test.InstrumentationTestRunne r不可修改
android:label="Testing"可不写
如出现Test run failed:Unable to find instrumentation target package
是因为 android:targetPackage= "com.neter.test.dao" 必须和
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package = "com.neter.test.dao" package 相同的包名