0

I want to assert the activity is finished after clicking a button. eg: if the user clicked button with id R.id.finish, then the activity is finished.

I'm trying to look up apis with ActivitySenerio and Espresso, but none of these helps.

Ref:

DevDengChao
  • 198
  • 15

1 Answers1

0

Without ActivitySenerio:

try {
    onView(withId(R.id.finish)).perform(click());
} catch (Exception e) {
    // assert the activity is finished
    assertEquals(NoActivityResumedException.class, e.getClass());
}

With ActivitySenerio(Rule):

    activity.findViewById(R.id.finish).performclick();
    assertTrue(activity.isFinishing());
DevDengChao
  • 198
  • 15