一、清单中注册
<span style="font-size:14px;"> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.itcast.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="android.test.runner"/> 1
<activity
android:name="cn.itcast.test.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.itcast.test" android:label="Tests for My App"/> 2,写要测试的包名
</manifest></span>
二、新建一个测试类,继承AndroidTest
<span style="font-size:14px;">public class PersonserviceTest extends AndroidTestCase {
public void testSave() throws Exception{
PersonService service = new PersonService();
service.save(null);
}
public void testAdd() throws Exception{
PersonService service = new PersonService();
int result = service.add(1,2);
Object actual = null;
Assert.assertEquals(3, actual);
}}</span>
* *File xmlFile = new File(getContext().getFilesDir(), "itcast.xml"); 内存中创建文件