Search code examples
androidtestingmanualandroid-espresso

Espresso automated and manual test at the same time


I am writing Espresso automated tests for an android app that interacts with an instrument through NFC tag. During the NFC read and manual interaction with the instrument, I want to halt the espresso test for 3-4 minutes. Can we have the automated and manual interaction at the same time during espresso tests? Is Idling resources an option as there are going to be UI changes during the halt?


Solution

  • Well, I don't get the idea of doing automated and manual testing at the same time, where automated tests in theory should speed up the process of checking user interactions with app and ease manual testers from some work.

    Doing manual tests in the middle of running automated Espresso tests is really a bad idea. It's very easy to interrupt tests or change a state of app, which would result in failed tests.

    On last Google Test Automation Conference 2015 was announced Barista - recorder for Espresso tests.

    In Espresso, I see three possible ways to do tests in your way:

    1. Make custom Idling resources class and register it.
    2. Use Java idling methods like Thread.sleep(240000);
    3. Write all automated tests you want to have, run them. Finally do selected manual tests.

    EDIT: According to your question the best idea is usingThead.sleep(milliseconds). It would stop the tests for desired amount of time like 3 or 4 minutes.

    But Espresso tests runs in random order so please reconfigure your existing configuration like this:

    In build.gradle declare in android -> defaultConfig your testInstrumentationRunner and of course Espresso, so your Gradle file should contains:

    android {
     defaultConfig {
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
               }
            }
        
     dependencies {  
       androidTestCompile 'com.android.support:support-annotations:23.+'
       androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
       androidTestCompile 'com.android.support.test:runner:0.4.1'
       androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
        /**
         * AccessibilityChecks
         * CountingIdlingResource
         * DrawerActions
         * DrawerMatchers
         * PickerActions (Time and Date picker)
         * RecyclerViewActions
         */
        } 
    

    Notice: The most important here is to declare AndroidJUnitRunner as your Espresso test runner, as we're gonna to use JUnit4 in our test configuration

    and finally change your test class code like this:

     @RunWith(AndroidJUnit4.class)
     @FixMethodOrder(MethodSorters.NAME_ASCENDING) 
     public class EspressoExampleTest {
    
     @Rule
     public ActivityTestRule<MainActivity> mRule = new ActivityTestRule<>(MainActivity.class);
    
     @Test
     public void checkIfAppNameIsDisplayed() {
         onView(withText(R.string.app_name)).check(matches(isDisplayed()));
     }
    

    Used here @FixMethodOrder(MethodSorters.NAME_ASCENDING) would give that your test classes would executed step by step, one after another, so let's say after your 8th test class you would put

     @Test
     public void waitUntilManualTestWoulBeDone() {
         Thread.sleep(1440000); //sleeps 4 minutes
     }
    

    It should work.