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

    onView(withId(R.id.changeTextBt)).perform(click());

    // Check that the text was changed.
    onView(withId(R.id.textToBeChanged)).check(matches(withText(STRING_TO_BE_TYPED)));
  }
Use {@link ActivityScenarioRule} to create and launch the activity under test.
ui/espresso/BasicSample/app/src/test/java/com/example/android/testing/espresso/BasicSample/ChangeTextBehaviorLocalTest.java