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

时间:2016-02-08 17:11:45

标签: android android-instrumentation

我设置了Espresso检测框架来运行我的Android Functional Automation测试。 对于每个测试,我想在完成测试后登录应用程序并删除应用程序。

所以,我设置如下:

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

}

2 个答案:

答案 0 :(得分:3)

无法从Instrumentation测试中卸载应用程序。但是,运行所有测试后,将自动卸载该应用程序。

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

答案 1 :(得分:0)

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

点击+->添加可识别gradle的Make-> :app:uninstallAll