Testing multiple activities with espresso

fernandohur picture fernandohur · Dec 6, 2013 · Viewed 36.8k times · Source

Is it possible to write tests across several activities using the android espresso framework?

Answer

Jigish Chawda picture Jigish Chawda · Dec 20, 2013

Yes, it is possible. In one of the samples they have demoed this here https://github.com/googlesamples/android-testing/blob/master/ui/espresso/BasicSample/app/src/androidTest/java/com/example/android/testing/espresso/BasicSample/ChangeTextBehaviorTest.java

@Test
public void changeText_newActivity() {
    // Type text and then press the button.
    onView(withId(R.id.editTextUserInput)).perform(typeText(STRING_TO_BE_TYPED),
            closeSoftKeyboard());
    onView(withId(R.id.activityChangeTextBtn)).perform(click());

    // This view is in a different Activity, no need to tell Espresso.
    onView(withId(R.id.show_text_view)).check(matches(withText(STRING_TO_BE_TYPED)));
}

Read the inline comment.

Waiting for the new activity to load is taken care of implicitly by Espresso.