How to test code built to save/restore Lifecycle of an Activity?

后端 未结 5 1463
醉话见心
醉话见心 2020-12-13 09:01

How can I test all of the following methods code? I want to play scenarios when all of them are happening to see if my code works for save/restore process of an activity. So

5条回答
  •  鱼传尺愫
    2020-12-13 09:16

    The testing tools offered by Android now offer a means of writing tests that can drive an activity from one state to another, or to recreate an activity to test the save and restore flow. See the Test your app's activities Android Developers documentation page for a list of the capabilities. An example of the syntax – taken from that page – is the following:

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

提交回复
热议问题