manifest中:
。。。
<uses-library android:name="android.test.runner" />
</application>
<uses-sdk android:minSdkVersion="8" />
<instrumentation
android:label="test my app"
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="cn.itcast.app" />
</manifest>
public class PersonServiceTest extends AndroidTestCase {
public void testSave() throws Exception{
PersonService ps =new PersonService();
ps.save(null);
}
public void testAdd() throws Exception{
PersonService ps =new PersonService();
Assert.assertEquals(3, ps.add(1, 2));
}
}
日志打印 logcat
public class PersonServiceTest extends AndroidTestCase {
public void testLogOut() throws Throwable{
//Log.i("123", "你么");
System.out.println("sdf你没");
}System.out.println("sdf你没"); 对应info
06-12 12:12:02.521: I/ System.out(738): sdf你没
System.err.println(""); 对应警告
本文介绍了一个具体的Android单元测试案例,包括如何使用AndroidTestCase进行服务层的测试,以及如何配置manifest文件来支持单元测试运行环境。此外,还展示了如何通过日志打印来进行调试。
1160

被折叠的 条评论
为什么被折叠?



