testing-state-restoration

Verify Jetpack Compose rememberSaveable state round-trips with StateRestorationTester.

303|10|Updated May 15, 2026
One-click install
npx skills add https://github.com/skydoves/android-testing-skills --skill testing-state-restoration
Or copy as Structured Prompt for Agentโ–ผ
Please help me install this Agent Skill.
Skill: testing-state-restoration
Source: https://github.com/skydoves/android-testing-skills/tree/main/compose/patterns/testing-state-restoration
Command: npx skills add https://github.com/skydoves/android-testing-skills --skill testing-state-restoration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you correctly verify that Jetpack Compose state saved with rememberSaveable actually round-trips through a save/restore cycle, avoiding false-positive tests that pass even when restoration did nothing.

Core Features & Use Cases

  • Validate rememberSaveable round-trips with StateRestorationTester by injecting a LocalSaveableStateRegistry, forcing a save โ†’ dispose โ†’ restore flow, and asserting restored values.
  • Correctly separate the two compositions by capturing state from the first composition and then nulling the reference before calling emulateSavedInstanceStateRestore to ensure you re-read from the restored composition.
  • Enforce restoration constraints including the 1 MB Bundle size limit and the requirement to use rememberSaveable (not plain remember) for persisted state.
  • Avoid incorrect lifecycle assumptions by clarifying what is not exercised (no Activity recreation, no real configuration-change lifecycle, no plain remember persistence).

Quick Start

Use the testing-state-restoration skill to verify that your Compose UI state survives rememberSaveable restore by using StateRestorationTester(rule) with restorationTester.setContent, driving the state to a non-default value, setting the state reference to null, then calling emulateSavedInstanceStateRestore and asserting the restored values.

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 that rememberSaveable state survives a configuration change in Jetpack Compose?โ–ผ

To test rememberSaveable state restoration in Jetpack Compose, use StateRestorationTester to emulate a save/restore round-trip via emulateSavedInstanceStateRestore, which validates state persistence without requiring a real Activity recreation or configuration-change lifecycle.

Why does my Compose UI testing pass for state restoration when rememberSaveable did nothing?โ–ผ

False-positive state restoration tests in Compose UI testing often occur when reusing references from the first composition, so you must hoist state as a nullable var, set it to null before calling emulateSavedInstanceStateRestore, and then assert values from the restored composition.

How do I use StateRestorationTester to verify Compose UI state?โ–ผ

Use StateRestorationTester with restorationTester.setContent instead of rule.setContent to inject a LocalSaveableStateRegistry, drive the state to a non-default value, null the state reference, call emulateSavedInstanceStateRestore, and assert the restored values.

Does remember work with emulateSavedInstanceStateRestore to persist Compose state?โ–ผ

No, plain remember does not persist state through emulateSavedInstanceStateRestore, so you must use rememberSaveable for any Compose UI state that needs to survive the save/restore round-trip and pass the restoration test.

What are the limitations of testing Compose state restoration with StateRestorationTester?โ–ผ

StateRestorationTester does not exercise real Activity recreation or configuration-change lifecycles, and the serialized saved bundle saved via rememberSaveable must be kept under the 1 MB Bundle size limit to avoid exceeding restoration constraints.

What is the best way to avoid false positives when testing rememberSaveable in Jetpack Compose?โ–ผ

The best way to avoid false positives when testing rememberSaveable is to correctly separate the two compositions by capturing state, nulling the reference before emulateSavedInstanceStateRestore, and asserting re-read values from the restored composition.