【发布时间】:2012-12-27 05:26:13
【问题描述】:
我正在使用junit 来测试我的安卓应用程序。在TestCase1.java 我点击“同意”按钮接受协议,然后断言一些可能性。
在下一个TestCase2.java 中,我想再次单击“同意”按钮并断言一些可能性。
每次运行测试用例时,我都必须卸载应用程序并重新安装它。如果我运行整个程序包,大多数情况下都会失败,因为我在重复相同的路径。
示例代码。
TestCase1.java
@Test
public void testdA_Case2() throws Exception {
solo.assertCurrentActivity("my test active", Myproj.class);
solo.clickOnButton("I Agree");
assertEquals(Getresponce(),"1");
}
TestCase2.java
@Test
public void testdA_Case2() throws Exception {
solo.assertCurrentActivity("my test active", Myproj.class);
solo.clickOnButton("I Agree");
assertEquals(register(), true);`
如何运行测试,以便在每个测试用例之前重新安装应用程序。如何自动化它。 (我尝试清除应用程序数据并尝试使用 Uri 卸载
packageURI = Uri.parse("package:"+"myproj.com");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(uninstallIntent);
` But my test stops running if I tried this.
提前感谢您的帮助。
【问题讨论】:
标签: android unit-testing junit4 uninstallation