Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso Instrumentation Tests - how to uninstall or delete the app after the test

I setup Espresso instrumentation framework to run my Android Functional Automation tests. For every test, I want to login to the app and delete the app after I finish the test.

So, I setup something like below:

public class FirstSampleTest extends 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 
}

}
like image 390
user5599934 Avatar asked Feb 08 '16 17:02

user5599934


2 Answers

You can add a gradle task in the Android Studio Before launch section in Run -> Edit Configurations.

Click + -> Add a gradle-aware Make -> :app:uninstallAll

note: "app" in :app:uninstallAll depends on your main module name. So it can be :my_module:uninstallAll, or :company:uninstallAll

like image 89
Allen Avatar answered Oct 22 '22 13:10

Allen


Uninstalling the app from the Instrumentation tests is not possible. However, once all the tests are run, the app is uninstalled automatically.

Note: The app is not uninstalled only when a single test is run. Please run the whole build using the command ./gradlew connectedAndroidTest

like image 3
user5599934 Avatar answered Oct 22 '22 14:10

user5599934