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

问题描述 投票:4回答:2

我设置了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 
}

}
android android-instrumentation
2个回答
3
投票

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

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


3
投票

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

单击+ - >添加gradle-aware Make - > :app:uninstallAll

© www.soinside.com 2019 - 2024. All rights reserved.