9

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

所以,我设置如下:

公共类 FirstSampleTest 扩展 BaseTest {

private final BaseTest baseTest;

// 私有 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 
}

}
4

2 回答 2

9

您可以在Android StudioBefore launch部分的Run -> Edit Configurations.

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

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

于 2019-02-28T16:26:55.313 回答
3

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

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

于 2016-02-10T11:25:06.147 回答