# StateRestorationTester

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

  ```
  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/junit4/ComposeContentTestRule#setContent(kotlin.Function0)` you need to use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/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/junit4/StateRestorationTester#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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester#setContent(kotlin.Function0)` and useful for testing `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/rememberSaveable.composable#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)` integration. It is not testing the integration with any other life cycles or Activity callbacks.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester#StateRestorationTester(androidx.compose.ui.test.junit4.ComposeContentTestRule)(composeTestRule: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeContentTestRule)` | android |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester#emulateSavedInstanceStateRestore()()` Saves all the state stored via savedInstanceState or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/rememberSaveable.composable#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)`, disposes current composition, and composes again the content passed to `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester#setContent(kotlin.Function0)`. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/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/junit4/ComposeContentTestRule#setContent(kotlin.Function0)` if you are going to use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester#emulateSavedInstanceStateRestore()` in the test. | android |

## Public constructors

### StateRestorationTester

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

```
StateRestorationTester(composeTestRule: ComposeContentTestRule)
```

## Public functions

### emulateSavedInstanceStateRestore

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

```
fun emulateSavedInstanceStateRestore(): Unit
```

Saves all the state stored via savedInstanceState or `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/rememberSaveable.composable#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0)`, disposes current composition, and composes again the content passed to `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/StateRestorationTester#setContent(kotlin.Function0)`. 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

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

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

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

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