StateRestorationTester


Helps to test the state restoration for your Composable component.

Instead of calling ComposeContentTestRule.setContent you need to use setContent on this object, then change your state so there is some change to be restored, then execute emulateSavedInstanceStateRestore and assert your state is restored properly.

Note that this tests only the restoration of the local state of the composable you passed to setContent and useful for testing androidx.compose.runtime.saveable.rememberSaveable integration. It is not testing the integration with any other life cycles or Activity callbacks.

Summary

Public constructors

android

Public functions

Unit

Saves all the state stored via savedInstanceState or rememberSaveable, disposes current composition, and composes again the content passed to setContent.

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

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

android

Public constructors

StateRestorationTester

StateRestorationTester(composeTestRule: ComposeContentTestRule)

Public functions

emulateSavedInstanceStateRestore

fun emulateSavedInstanceStateRestore(): Unit

Saves all the state stored via savedInstanceState or rememberSaveable, disposes current composition, and composes again the content passed to setContent. Allows to test how your component behaves when the state restoration is happening. Note that the state stored via regular state() or remember() will be lost.

setContent

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

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

See also
setContent