0

If I have a MainActivity and a DetailActivity, how can I test that the DetailActivity has been launched?

public class MainScreenTest {

    @Rule
    public IntentsTestRule<MainActivity> mainActivityRule =
            new IntentsTestRule<>(MainActivity.class);

    @Test
    public void shouldOpenDetailActivityOnClick() {
        onView(withId(R.id.button)).check(matches(withText("Detail")));

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

        ...
    }

}
David
  • 4,191
  • 2
  • 31
  • 40

1 Answers1

0

Here is one way of doing it:

public class MainScreenTest {

    @Rule
    public IntentsTestRule<MainActivity> mainActivityRule =
            new IntentsTestRule<>(MainActivity.class);

    @Test
    public void shouldOpenDetailActivityOnClick() {
        onView(withId(R.id.button)).check(matches(withText("Detail")));

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

        intended(hasComponent("com.example.androidplayground.DetailActivity"));
    }

}
David
  • 4,191
  • 2
  • 31
  • 40