@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());

    // An intent is fired to launch a different Activity. Robolectric doesn't currently
    // support launching a new Activity, so use Espresso Intents to verify intent was sent
    assertThat(Iterables.getOnlyElement(Intents.getIntents())).hasComponentClass(
        ShowTextActivity.class);
  }
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