0

I have a testsuite which has mutiple testcases in a class every test case is isolated So when i execute the testsuite class i want to restart the app for every testcase

How do i relaunch application from start for every individual test case in Espresso

Thanks in advance

@Test
public void testcase1() {
//from first screen
}

@Test
public void testcase2() {
//from first screen
}
SHASHIDHAR MANCHUKONDA
  • 3,302
  • 2
  • 19
  • 40
  • Similar question was answered by me here https://stackoverflow.com/questions/54079434/properly-cleanup-teardown-after-instrumentation-test-only-when-app-is-100-fin/54163572#54163572 – denys Apr 08 '19 at 13:49

3 Answers3

0

There is another stack overflow answer that seems to answer this question. If you were looking to do that in Kotlin though I converted the answer to relaunch multiple times for different tests.

@RunWith(AndroidJUnit4::class)
class ExampleEspressoTest {

    @get:Rule
    val rule = ActivityTestRule(
        activityClass = MainActivity::class.java,
        initialTouchMode = false,
        launchActivity = false) //set to false to customize intent

    @Test
    fun testCustomIntent() {
        val intent = Intent().apply {
            putExtra("your_key", "your_value")
        }
        rule.launchActivity(intent)

        //continue with your test
    }

}
Andrew Steinmetz
  • 1,010
  • 8
  • 16
  • I have multiple cases in single suite and all are independent Test public void testcase1() { //from first screen } Test public void testcase2() { //from first screen } – SHASHIDHAR MANCHUKONDA Mar 20 '19 at 10:01
0

If you need to start a method/test and when it's finished clear data and start the next one, you should use commands.

Look at this documentation: https://developer.android.com/studio/test/command-line

I'm using this command:

./gradlew testVariantNameUnitTest --tests *.sampleTestMethod
0

There could be several ways to do this but we wanted a way that works both locally as well as google fire base test lab, so ended up with using configuration in build.gradle file under default config.

defaultConfig{ 
   testInstrumentationRunnerArguments clearPackageData: 'true'
}

Reference: https://developer.android.com/training/testing/junit-runner#ato-gradle

Also you use these runner arguments for configuring different tests you wanted run based on build variants or other config options, look at my post if you want more detail.

satyajit
  • 1,470
  • 3
  • 22
  • 43