[Android] Running multiple tests without reinitiate the application again


I’m new to appium and this might be a simple issue that I might somehow overlooked or didn’t find a solution yet by searching the documentation.

I’m trying to automate an Android application, with JUnit as the test runner. My tests are structured into files that are containing @Before, @After and @Test.

public class LoginWithInvalidCredentials {

private AppiumDriver driver;

private String ValidEmail = "[email protected]";
private String InvalidPassword = "Qwerty@1";

public void setUp() throws Exception    {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "AndroidTestDevice");

    driver = new AndroidDriver(new URL(""), capabilities);

public void tearDown() throws Exception {


public void LoginWithInvalidCredentials() {`indent preformatted text by 4 spaces`

The suite is started by running a file that looks like this

        LoginWithInvalidCredentials.class, LoginWithInvalidMail.class, Login.class })

public class TestSuiteAll {


The thing that I want to solve is that each time a class is initiated the application is reinitiated / reinstalled again, making the time of the test execution to be long.

I want to know if there’s any method to make my class files run one after the other without reinitiate the application - because now they are checking things in the same screen - so I want to send keys on different scenarios and check some error message based on the scenario.

Thank you,

Check this webpage :-


Hope it helps you!!

@jitenderbhardwaj thank you very much for your help, but my scenario, is a bit different than what you explained in your blog post. I will try to adapt what I’ve seen in your code snippets there, but I think there are better ways to do in my case - especially because it’s mobile.

Thank you,

The @Before and @After blocks are executed for each @Test. If there are many of @Test methods, then you’ll have to go through the initiation and cleanup phases multiple times.

One way around this is to change your @Before and @After annotations to @BeforeClass and @AfterClass annotations, so the initiation and cleanup is performed once per class. There is still some initiation and cleanup for each test however; you want to call driver.resetApp() at the beginning or end of each test (possibly both at beginning and end) with the latest version of Appium with the latest version of all dependencies (in other words, you’re using the command line version of Appium, installed using npm with the --no-shrinkwrap option).

Have you considered TestNG as an alternative to JUnit?