StateRestorationTester

Class

Common
@ExperimentalTestApi
class StateRestorationTester(private val composeTest: ComposeUiTest)

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.

Functions

fun setContent(composable: @Composable () -> Unit)

This functions is a direct replacement for ComposeUiTest.setContent if you are going to use emulateSaveAndRestore in the test.

fun emulateSaveAndRestore()

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.