# StateRestorationTester

Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/StateRestorationTester.kt+class:androidx.compose.ui.test.StateRestorationTester) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0) Common/AllAndroid/JVM
- Cmn

  ```
  @ExperimentalTestApi
  class StateRestorationTester
  ```

*** ** * ** ***

Helps to test the state restoration for your Composable component.

Instead of calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#setContent(kotlin.Function0)` you need to use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#setContent(kotlin.Function0)` on this object, then change your state so there is some change to be restored, then execute `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#setContent(kotlin.Function0)` and it is useful for testing uses of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/rememberSaveable.composable#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)`. It is not testing the integration with app and/or platform specific lifecycles.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#StateRestorationTester(androidx.compose.ui.test.ComposeUiTest)(composeTest: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest)` | Cmn |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#emulateSaveAndRestore()()` Emulates a save and restore cycle of the current composition. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#setContent(kotlin.Function0)(composable: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` This functions is a direct replacement for `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#setContent(kotlin.Function0)` if you are going to use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#emulateSaveAndRestore()` in the test. | Cmn |

## Public constructors

### StateRestorationTester

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
StateRestorationTester(composeTest: ComposeUiTest)
```

## Public functions

### emulateSaveAndRestore

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
fun emulateSaveAndRestore(): Unit
```

Emulates a save and restore cycle of the current composition. First all state that is remembered with `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/rememberSaveable.composable#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)` 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 `https://developer.android.com/reference/kotlin/androidx/compose/runtime/remember.composable#remember(kotlin.Function0)` will be lost.

### setContent

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

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

This functions is a direct replacement for `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#setContent(kotlin.Function0)` if you are going to use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/StateRestorationTester#emulateSaveAndRestore()` in the test.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#setContent(kotlin.Function0)` |   |