Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for another activity to start with Espresso?

How can I make a test that waits for an Activity to start whenever a button is clicked?

My test is really simple:

public void testStartsNewActivity() {
   onView(withId(R.id.button)).perform(click());
   // assert new Activity is launched
}

thanks!

like image 488
Javier Manzano Avatar asked May 18 '15 14:05

Javier Manzano


1 Answers

Asserting that a new activity has been launched is as easy as asserting that a view belonging to that new activity is displayed on the screen.

Check this for more samples. Additional info:

By default, Espresso waits for UI events in the current message queue to process and default AsyncTasks* to complete before it moves on to the next test operation. This should address the majority of application/test synchronization in your application.

Thus, given your "really simple" test case, I'm assuming there's no waiting on custom resource loading and asserting that a view is displayed should be enough.

like image 133
appoll Avatar answered Oct 13 '22 00:10

appoll