android - Espresso Instrumentation Tests - 如何在测试后卸载或删除应用程序

标签 android android-instrumentation

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

所以,我设置如下:

公共(public)类 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 
}

}

最佳答案

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

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

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

关于android - Espresso Instrumentation Tests - 如何在测试后卸载或删除应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35275345/

相关文章:

android - 如何在跳过循环后调试 for 循环

Android - 使用 CommonWare 的 locpoller 时出现问题

android - ActivityTestRule 在 android 测试中被弃用

Android Espresso 测试失败并出现 IncompleteClassChangeError

java - Android Studio "Sources for Android API Platform 30 Not Found"

android - 在 MainActivity 中创建对话框并在整个应用程序的 fragment 中使用它

android - 如何使edittext View 填充android中的父元素

Android Studio Junit 测试包 org.junit 不存在

android - 应用程序启动何时涉及仪器?