controlling-the-test-clock

Drive Compose UI test progression with frame-accurate MainTestClock time advancement.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the confusion of how Compose UI tests progress through time—especially when animations, recomposition, and async coroutines depend on the test clock—so your assertions match what the framework actually did.

Core Features & Use Cases

  • Frame-accurate clock control: Advance time by exactly one frame with MainTestClock.advanceTimeByFrame, or step by durations with the correct rounding rules.
  • Deterministic animation timing: Understand the 16 ms frame model and the “kick-off” frame so animations start with the right play time.
  • v1 to v2 migration reliability: Use runCurrent or advanceTimeBy(0) after state mutations when v2 createComposeRule queues work under the StandardTestDispatcher.
  • Test-clock waiting & failure diagnosis: Use advanceTimeUntil for Compose-state conditions and correctly interpret ComposeTimeoutException as a verdict on unmet snapshot/state changes.

Quick Start

Use the controlling-the-test-clock skill to explain why your Compose test clock needs an extra advanceTimeByFrame after setContent and how to fix timing issues caused by v2 task queuing.

Frequently Asked Questions about controlling-the-test-clock

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

FAQPage Schema
How do I control Jetpack Compose animation timing in UI tests?

To fix ComposeTimeoutException in UI tests, use advanceTimeUntil to wait for specific Compose state conditions. This exception indicates unmet snapshot or state changes, meaning the test clock must advance further to process queued tasks before UI assertions can succeed.

Why do my Compose UI tests fail after migrating to v2 createComposeRule?

Compose UI tests fail after migrating to v2 createComposeRule because StandardTestDispatcher changes task scheduling semantics. You must call runCurrent or advanceTimeBy(0) after state mutations to drain queued snapshot writes before executing UI assertions.

How do I advance the test clock by exactly one frame in Compose tests?

To advance the test clock by exactly one frame in Compose tests, call MainTestClock.advanceTimeByFrame. This drives the shared TestCoroutineScheduler deterministically, accounting for the 16 ms frame model and the kick-off frame required for accurate animation play time.

Do I need to call runCurrent after setContent in Compose v2 test rules?

Yes, you need to call runCurrent or advanceTimeBy(0) after setContent in Compose v2 test rules. Because v2 createComposeRule queues work under StandardTestDispatcher, draining these queued snapshot writes ensures recomposition finishes before assertions.

What causes ComposeTimeoutException when waiting for state changes?

ComposeTimeoutException occurs when waiting for state changes if the test clock space is not advanced properly. It serves as a verdict on unmet snapshot or state conditions, indicating that advanceTimeUntil failed to satisfy the required Compose state within the timeout.