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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With