How to test saving and restoring state of an android activity with Espresso?

前端 未结 3 1994
别那么骄傲
别那么骄傲 2021-02-09 08:53

Is there a way of testing the save and restore state code of an activity programmatically ? I mean doing this :

How to test code built to save/restore Lifecycle of an A

3条回答
  •  执笔经年
    2021-02-09 09:43

    The testing tools offered by Android now offer a means of writing UI tests that can recreate an activity to test the save and restore flow. See the Recreate the activity section within the Test your app's activities Android Developers documentation page. An example of the syntax – taken from that page – is the following:

    @RunWith(AndroidJUnit4::class)
    class MyTestSuite {
        @Test fun testEvent() {
            val scenario = launchActivity()
            scenario.recreate()
        }
    }
    

提交回复
热议问题