Android实例系列---03.Android中的Junit单元测试

1.AndroidManifest.xml配置

application内

<uses-library android:name="android.test.runner" />
 

application外

<instrumentation android:name="android.test.InstrumentationTestRunner"
  android:targetPackage="cn.netcenter.test" android:label="Tests for My App" />

2.测试方法命名以test开头如:testSave()

private static final String TAG = "PersonServiceTest";

	public void testSave() throws Throwable{
		PersonService service = new PersonService();
		int b = service.save();//检验save()方法运行是否正常
		//Log.i(TAG, "result="+ b);
		//System.out.println();
		//System.err.println("result="+ b);
		Assert.assertEquals(78, b);
	}
 

相关推荐