【问题标题】:Espresso Instrumentation Tests - how to uninstall or delete the app after the testEspresso Instrumentation 测试 - 如何在测试后卸载或删除应用程序
【发布时间】:2019-10-15 17:30:20
【问题描述】:

我设置了 Espresso 检测框架来运行我的 Android 功能自动化测试。 对于每次测试,我都想在完成测试后登录应用程序并删除应用程序。

所以,我设置如下:

公共类 FirstSampleTest 扩展 BaseTest {

private final BaseTest baseTest;

// private final ElementUtils elementUtils;

public FirstSampleTest() throws InterruptedException {
    this.baseTest = new BaseTest();
}

@Before
public void initiate() throws InterruptedException {
    //I have setup login method here to login to the app after it installs
}

@Rule
public ActivityTestRule<SplashScreenActivity> splashScreenActivityActivityTestRule = new ActivityTestRule(SplashScreenActivity.class);

@Test
public void testTheHomeScreen() throws InterruptedException {
   //Some tests go here. 
}

@After
public void teardown() throws InterruptedException {
    //I want to uninstall the app or delete it from the emulator once the test is run 
}

}

【问题讨论】:

    标签: android android-instrumentation


    【解决方案1】:

    您可以在Run -&gt; Edit Configurations 的 Android Studio Before launch 部分中添加 gradle 任务

    点击+ -> 添加一个gradle-aware Make -> :app:uninstallAll

    注意::app:uninstallAll 中的“app”取决于您的 ma​​in 模块名称。所以可以是:my_module:uninstallAll,或者:company:uninstallAll

    【讨论】:

    • 在执行此操作时,如果插入了无关的、可调试的 Android 设备,请小心。 :app:uninstallAll 似乎在 所有 可用设备上卸载了您的应用(与当前打开的项目关联的应用)。
    【解决方案2】:

    无法从 Instrumentation 测试中卸载应用。但是,一旦运行所有测试,应用程序就会自动卸载。

    注意:仅在运行单个测试时才会卸载该应用程序。请使用命令运行整个构建 ./gradlew connectedAndroidTest

    【讨论】:

    • 我认为 user5599934 是在谈论测试本身被删除,而不是你的实际应用程序。我认为您的问题是如何在测试之间删除该实际应用程序,这是我想要做的能够测试我的新 API 24 权限代码的事情。这是一种方法stackoverflow.com/questions/20705711/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多