外部测试项目实现:
1、配置环境
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="cn.itcast.test" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
//////进行单元测试的包路径设置
<uses-library android:name="android.test.runner" />
</app
ication```
2、单元测试类AndroidTestCase
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 actual = service.add(1, 2);
//验证测试结果--预言
Assert.assertEquals(3, actual);
}
}
“`
3、通过junit的视图查看相关情况
本文详细介绍了如何在Android中使用InstrumentationTestRunner进行单元测试,包括环境配置和测试类的编写。通过具体的PersonServiceTest案例,展示了如何继承AndroidTestCase类来创建测试用例,并利用JUnit进行测试结果的查看。
861

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



