synchronizing-with-idle

Select correct idle-waiting primitives and timeout sources for Jetpack Compose UI tests.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It eliminates flaky Jetpack Compose UI tests caused by waiting on the wrong synchronization primitive, using wall-clock time where deterministic test-clock progression is required, or reading/mutating Compose state from the wrong thread.

Core Features & Use Cases

  • Idle semantics and decision matrix: Defines what “idle” means in Compose tests (recompositions drained, draw ready, and all registered IdlingResources are idle) and helps you pick the correct API among waitForIdle/awaitIdle, waitUntil*, runOnIdle, runOnUiThread, runWhenIdle, awaitAndRunWhenIdle, and hasPendingWork.
  • Correct timeout sourcing: Explains the wall-clock vs test-clock split so you use waitUntil for non-Compose conditions and mainClock.advanceTimeUntil for Compose-state-observable conditions.
  • Thread-safety guardrails: Prevents stale reads by funneling test-thread state reads through runOnIdle (and correct mutation behavior through runOnUiThread under a paused clock).
  • External async synchronization: Shows when and how to register an Espresso/Compose-compatible IdlingResource so HTTP/DB-style work participates in waits reliably.

Quick Start

Use this skill to choose the exact ComposeTestRule/ComposeUiTest wait or idle API for your flaking UI test and fix the timeout source and thread access pattern based on what your condition depends on.

Frequently Asked Questions about synchronizing-with-idle

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

FAQPage Schema
Why are my Jetpack Compose UI tests flaky and how do I fix the idle waiting?

Compose UI test flakiness often stems from waiting on the wrong synchronization primitive. You can resolve it by selecting the correct idle-wait API and ensuring timeout sources match whether your condition relies on wall-clock or test-clock progression.

How do I use waitUntil vs mainClock.advanceTimeUntil for Jetpack Compose testing?

Use waitUntil for non-Compose conditions running on wall-clock time, and use mainClock.advanceTimeUntil for Compose-state-observable conditions. Distinguishing wall-clock waitUntil from test-clock advanceTimeUntil behavior ensures deterministic test-clock progression.

When should I use runOnIdle and runOnUiThread in Compose UI tests?

Use runOnIdle to safely read Compose state from the test thread, preventing stale reads. Use runOnUiThread for correct state mutation behavior under a paused test clock, funneling state access safely during assertion-heavy blocks.

How do I synchronize Jetpack Compose tests with external async work like HTTP or DB tasks?

To synchronize Compose tests with external async work, register an Espresso and Compose-compatible IdlingResource. This ensures HTTP or DB-style background work reliably participates in idle waits and prevents premature assertions.

What does "idle" mean in Jetpack Compose UI testing?

In Compose UI testing, idle means all recompositions are drained, the draw is ready, and all registered IdlingResources are idle. Defining idle precisely helps you select the correct API among waitForIdle, awaitIdle, and runWhenIdle.

Does Espresso IdlingResource work with Jetpack Compose UI tests?

Yes, you can register an Espresso and Compose-compatible IdlingResource so external async work participates in waits reliably. This integration ensures background tasks like HTTP or DB operations are tracked during Compose test synchronization.