Android testing: asserting an activity transitioned to another -


i looking @ tests on android activities. test activity lifecycle , particularly end of activity start activity (i testing end of first activity, not start of second). using activityinstrumentationtestcase2 , android espresso junit 4 tests.

i have tried assert once trigger end of activity, pressing button on screen, activity paused or not visible ran out of luck far. there practice test transitions between activities?

you should take @ https://developer.android.com/training/activity-testing/activity-functional-testing.html#activitymonitor.

basically you'll need add , register activitymonitor in instrumented functional test, set listen second activity. once trigger happens (ie button being clicked in test case) use waitforactivitywithtimeout(int) instance of second activity.

if call times out, or result null, know second activity hasn't been started. can assert on activity instances whether they're finishing/destroyed/etc depending on expecting happen them.


Comments