testing-state-restoration

Tests rememberSaveable state round-trips in Jetpack Compose using StateRestorationTester.

1|Updated Jul 6, 2026
One-click install
npx skills add https://github.com/citytexi/team-yg-pesonal-agent --skill testing-state-restoration-citytexi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: testing-state-restoration
Source: https://github.com/citytexi/team-yg-pesonal-agent/tree/main/.claude/skills/testing-state-restoration
Command: npx skills add https://github.com/citytexi/team-yg-pesonal-agent --skill testing-state-restoration-citytexi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Compose UI tests often claim to verify state restoration but silently prove nothing: they re-read the same state instance, call the wrong setContent overload, or use plain remember which never survives a save/restore cycle. This Skill provides the canonical StateRestorationTester workflow so tests genuinely prove that rememberSaveable state survives process death and configuration change emulation. ## Core Features & Use Cases - Correct round-trip structure: Enforces constructing StateRestorationTester from a ComposeContentTestRule, calling restorationTester.setContent instead of rule.setContent, and nulling the hoisted state reference between phases so the assertion reads the post-restoration composition. - Wrong vs right patterns: Contrasts remember vs rememberSaveable, rule.setContent vs tester.setContent, and re-reading the same instance vs nulling between phases, with cited AOSP source lines. - Boundary awareness: Documents the 1 MB Bundle cap, incompatibility with createEmptyComposeRule, and what the tester does NOT cover (Activity recreation, ViewModel SavedStateHandle). - Use Case: A developer writes a regression test proving a LazyColumn scroll position survives process death; the Skill guides them to scroll to a non-default index, capture values in runOnIdle, null the state, call emulateSavedInstanceStateRestore, and assert equality. ## Quick Start Write a Compose UI test that verifies a rememberSaveable value survives a save and restore cycle using StateRestorationTester.

Frequently Asked Questions about testing-state-restoration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test rememberSaveable state restoration in Jetpack Compose?▼

Use StateRestorationTester constructed from a ComposeContentTestRule, call restorationTester.setContent, drive the state to a non-default value, null the hoisted state reference, then call emulateSavedInstanceStateRestore and assert the restored values inside runOnIdle.

Why does emulateSavedInstanceStateRestore throw setContent should be called first?▼

The error occurs when content was set via rule.setContent instead of restorationTester.setContent. Only the tester injects the LocalSaveableStateRegistry, so calling the rule directly leaves the registry null and the restore call fails.

Does StateRestorationTester work with plain remember instead of rememberSaveable?▼

No. State stored via plain remember or mutableStateOf not behind rememberSaveable is lost during the save/restore round-trip, as stated in the StateRestorationTester KDoc. Only state registered through SaveableStateRegistry survives.

Can StateRestorationTester test Activity recreation or configuration changes?▼

No. It only emulates the save/restore of the SaveableStateRegistry and does not restart the Activity, trigger lifecycle callbacks, or rebind ViewModels. Use Espresso ActivityScenario.recreate for Activity recreation coverage.

Why does my state restoration test fail with Bundle exceeds maximum size?▼

StateRestorationTester enforces a 1 MB cap on the serialized Bundle, matching real Binder transaction limits. Persist large data via Room or DataStore and save only a stable id or key through rememberSaveable.

Can I use StateRestorationTester with createEmptyComposeRule?▼

No. createEmptyComposeRule returns ComposeTestRule, which lacks setContent, while StateRestorationTester requires a ComposeContentTestRule. Use createComposeRule or createAndroidComposeRule instead.