Testing multiple activities with espresso

前端 未结 4 818
無奈伤痛
無奈伤痛 2020-12-12 22:03

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

4条回答
  •  情话喂你
    2020-12-12 22:49

    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.

提交回复
热议问题