【问题标题】:How to uninstall and reinstall application while running each test cases如何在运行每个测试用例时卸载和重新安装应用程序
【发布时间】: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


    【解决方案1】:

    您似乎无法从测试用例中重新安装您的 apk,因为它们都在应用程序中运行。

    但您可以从外部实现所需的流量控制。

    从批处理/shell 脚本中,您可以根据需要调用 adb install -r .... 并运行单独的测试项目。以下是运行方法:Running Android Junit tests from command line

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-28
      • 2016-07-11
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-26
      相关资源
      最近更新 更多