Compose state restore tests
Tests that Compose screens keep their state after process death with StateRestorationTester.
Claude's review
8/10 StateRestorationTester with the load-bearing null-between-phases trick, cited.
We asked Claude the question you would ask: would I be glad I installed this? We only sell skills it rates 7 or higher.
In detail
Use this skill to test `rememberSaveable` round-trips with `StateRestorationTester`, the only supported tool for proving Compose state survives process death and configuration change. Covers the constructor (`StateRestorationTester(rule: ComposeContentTestRule)`), why `restorationTester.setContent { }` MUST replace `rule.setContent { }`, the `state = null` between phases trick that proves restoration actually happened, the 1 MB Bundle cap, and what is NOT exercised (Activity lifecycle, configuration changes, plain `remember`). Use when the developer asks "how do I test rememberSaveable", "test state survives rotation", "state is lost after restore", "Bundle exceeds maximum size", or shows a test that re-reads the same state reference after `emulateSavedInstanceStateRestore` and is confused why nothing changed.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: testing-state-restoration
description: >-
Use this skill to test `rememberSaveable` round-trips with `StateRestorationTester`, the only supported tool for proving Compose state survives process death and configuration change. Covers the constructor (`StateRestorationTester(rule: ComposeContentTestRule)`), why `restorationTester.setContent { }` MUST replace `rule.setContent { }`, the `state = null` between phases trick that proves restoration actually happened, the 1 MB Bundle cap, and what is NOT exercised (Activity lifecycle, configuration changes, plain `remember`). Use when the developer asks "how do I test rememberSaveable", "test state survives rotation", "state is lost after restore", "Bundle exceeds maximum size", or shows a test that re-reads the same state reference after `emulateSavedInstanceStateRestore` and is confused why nothing changed.
license: Apache-2.0. See LICENSE for complete terms.
metadata:
author: Jaewoong Eum (skydoves)
keywords:
- jetpack-compose
- ui-testing
- state-restoration-tester
- rememberSaveable
- SaveableStateRegistry
- emulateSavedInstanceStateRestore
- process-death
- configuration-change
- parcel
---
# Testing State Restoration — `StateRestorationTester` Round-Trips Only `rememberSaveable`
`StateRestorationTester` is the only first-party way to verify that a Composable's state survives a save/restore cycle. It is narrow — it injects a `LocalSaveableStateRegistry`, snapshots whatever registered through it, throws away the composition, and re-composes with the snapshot restored. It does **not** restart the Activity, it does **not** trigger `Application.onCreate`, and it has a hard 1 MB cap on the serialized Bundle. Misunderstanding the scope produces tests that look passing but prove nothing.
## When to use this skill
- The developer is verifying that `rememberSaveable` survives — for a `LazyListState`, a TextField value, a screen toggle, etc.
- The developer asks "how do I test `rememberSaveable` in a unit test?"
- A test calls `emulateSavedInstanceStateRestore()` and the state appears unchanged or null.
- The developer hits `IllegalStateException: Bundle exceeds maximum size (1 MB)`.
- A reviewer asks for a regression test for a save/restore bug fix.
## When NOT to use this skill
- The bug under test is an **Activity recreation** issue (rotation re-creates the Activity, callbacks fire, ViewModels rebind). `StateRestorationTester` does not exercise that path; use Espresso `ActivityScenario.recreate()` plus this skill if both phases need coverage.
- The state is in a `ViewModel` and the developer wants to test `SavedStateHandle`. Use the AndroidX ViewModel testing tools.
- The class skeleton is wrong — fix `../structuring-a-compose-test/SKILL.md` first.
## Prerequisites
- `androidx.compose.ui:ui-test-junit4` on `androidTestImplementation`. `StateRestorationTester` is in package `androidx.compose.ui.test.junit4`.
...From skydoves's repository, Apache-2.0 licence.
Related skills
-
Checked
Android Gradle Plugin upgrade
Moves Kotlin Multiplatform projects to Android Gradle Plugin 9 and fixes the build failures it causes.
8/101 credit -
Checked
CocoaPods to SwiftPM
Moves Kotlin Multiplatform projects from CocoaPods to Swift Package Manager and updates the Xcode project.
8/101 credit -
Checked
Kotlin Native build speed
Diagnoses and fixes slow Kotlin/Native iOS builds in Kotlin Multiplatform projects, both locally and on CI.
8/101 credit -
Checked
SwiftUI Liquid Glass
Adds and reviews Liquid Glass in SwiftUI apps for iOS 26, avoiding pitfalls with bars, buttons and scrolling.
8/101 credit -
Checked
Compose Multiplatform UI
Builds one shared Compose UI in Kotlin for Android, iOS and desktop, so you write your screens once.
7/101 credit -
Checked
SwiftUI Mac app rules
Writes and debugs Swift 6 and SwiftUI code for Mac apps, fixing concurrency, state and common compiler errors.
7/101 credit