StateRestorationTester

class StateRestorationTester
kotlin.Any
   ↳ androidx.ui.test.StateRestorationTester

Helps to test the state restoration for your Composable component.

Instead of calling ComposeTestRule.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 savedInstanceState or rememberSavedInstanceState integration. It is not testing the integration with any other life cycles or Activity callbacks.

Summary

Public constructors

<init>(composeTestRule: ComposeTestRule)

Helps to test the state restoration for your Composable component.

Public methods

Unit

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

Unit
setContent(composable: <ERROR CLASS>, Unit: <ERROR CLASS>)

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

Public constructors

<init>

StateRestorationTester(composeTestRule: ComposeTestRule)

Helps to test the state restoration for your Composable component.

Instead of calling ComposeTestRule.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 savedInstanceState or rememberSavedInstanceState integration. It is not testing the integration with any other life cycles or Activity callbacks.

Public methods

emulateSavedInstanceStateRestore

fun emulateSavedInstanceStateRestore(): Unit

Saves all the state stored via savedInstanceState or rememberSavedInstanceState, 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: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Unit

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