StateRestorationTester
-
Cmn
@ExperimentalTestApi
class StateRestorationTester
Helps to test the state restoration for your Composable component.
Instead of calling ComposeUiTest.setContent you need to use setContent on this object, then change your state so there is some change to be restored, then execute emulateSaveAndRestore and assert your state is restored properly.
Note that this only tests the restoration of the local state of the composable you passed to setContent and it is useful for testing uses of rememberSaveable. It is not testing the integration with app and/or platform specific lifecycles.
Summary
Public constructors |
|
|---|---|
StateRestorationTester(composeTest: ComposeUiTest) |
Cmn
|
Public functions |
||
|---|---|---|
Unit |
Emulates a save and restore cycle of the current composition. |
Cmn
|
Unit |
setContent(composable: @Composable () -> Unit)This functions is a direct replacement for |
Cmn
|
Public constructors
Public functions
emulateSaveAndRestore
fun emulateSaveAndRestore(): Unit
Emulates a save and restore cycle of the current composition. First all state that is remembered with rememberSaveable is stored, then the current composition is disposed, and finally the composition is composed again. This allows you to test how your component behaves when state restoration is happening. Note that state stored via remember will be lost.
setContent
fun setContent(composable: @Composable () -> Unit): Unit
This functions is a direct replacement for ComposeUiTest.setContent if you are going to use emulateSaveAndRestore in the test.
| See also | |
|---|---|
setContent |