testing-state-restoration
Installation
SKILL.md
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
rememberSaveablesurvives — for aLazyListState, a TextField value, a screen toggle, etc. - The developer asks "how do I test
rememberSaveablein 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).
StateRestorationTesterdoes not exercise that path; use EspressoActivityScenario.recreate()plus this skill if both phases need coverage. - The state is in a
ViewModeland the developer wants to testSavedStateHandle. Use the AndroidX ViewModel testing tools. - The class skeleton is wrong — fix
../structuring-a-compose-test/SKILL.mdfirst.