I\'m trying to implement some navigation tests with espresso. Actually i want to check if the application has been closed by the use of the Back key on the main screen, just
Short answer:
Use Espresso.pressBackUnconditionally()
.
I've checked for version 3.1.1
Example:
Espresso.pressBackUnconditionally()
assertTrue(activityRule.activity.isDestroyed)
Explonation:
As you can see in Expresso source code it passes false
flag to PressBackAction
, so that it doesn't throw exception.