Android Espresso : correctly test closing app with pressBack

前端 未结 1 1267
情书的邮戳
情书的邮戳 2021-01-18 03:29

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

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 03:56

    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.

    0 讨论(0)
提交回复
热议问题