----------------新建DemoDao.java--------------
packagecom.neter.test.dao;
import android.util.Log;
public class DemoDao{
publicvoid
save(){
Log.i("DemoDao","用来测试的方法");
}
}
----------------新建DemoDaoTest.java--------------
packagecom.neter.test.dao;
import android.test.AndroidTestCase;
import android.util.Log;
public class DemoDaoTestextends
AndroidTestCase{
publicvoid
testSave(){
newDemoDao().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-sdkandroid:minSdkVersion="8"
/>
<applicationandroid:icon="@drawable/icon"
android:label="@string/app_name">
<uses-libraryandroid:name="android.test.runner"/>
<activityandroid:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<instrumentationandroid:name="android.test.InstrumentationTestRunner"android:targetPackage="com.neter.test.dao"android:label="Testing"></instrumentation>
</manifest>
上面配置文件中
MainActivity为android程序入口,请自已新建代码略
<uses-library android:name="android.test.runner"/>不可修改
android:name="android.test.InstrumentationTestRunner不可修改
android:label="Testing"可不写
如出现Test run failed:Unable to find instrumentation target package
是因为 android:targetPackage="com.neter.test.dao"必须和
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.neter.test.dao"
package相同的包名