compose-ui-testing-patterns

Guides writing and reviewing Jetpack Compose UI, screenshot, and interaction-state tests.

Updated Jul 1, 2026
One-click install
npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill compose-ui-testing-patterns-w0lzard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-ui-testing-patterns
Source: https://github.com/w0lzard/Wolzard-s-Marketplace/tree/main/plugins/personal-skills/skills/compose-ui-testing-patterns
Command: npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill compose-ui-testing-patterns-w0lzard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Compose UI tests often become flaky, over-scoped, or assert the wrong thing — full app graphs built to test an error row, screenshot tests for simple text, or fragile pointer simulation for hover states. This Skill provides decision rules and patterns for choosing the right test shape and writing deterministic Compose tests. ## Core Features & Use Cases - Test target selection: A decision table mapping what you need to prove (text, callbacks, focus, visuals, navigation) to the right test shape — plain UI test, screenshot test, or integration test. - Interaction state testing: Patterns for injecting MutableInteractionSource and emitting hover, press, focus, and drag interactions from a test coroutine scope instead of simulating pointer events. - Deterministic screenshot tests: Guidance on faking image loaders, freezing clocks, and fixing state so visual assertions stay stable. - Use Case: When reviewing a PR, you spot a UI test that builds the full DI graph just to verify an error message appears. This Skill tells you to test the plain state-driven composable with state = Error and a semantics assertion instead. ## Quick Start Ask the AI to review or write a Jetpack Compose UI test for a screen using these testing patterns.

Frequently Asked Questions about compose-ui-testing-patterns

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

FAQPage Schema
How do I test hover or pressed states in Jetpack Compose?

Inject a MutableInteractionSource into the composable and emit interactions like HoverInteraction.Enter or PressInteraction.Press from a test coroutine scope, then call waitForIdle and assert the resulting visual or semantic change. Do not simulate pointer or mouse events, which is flaky.

When should I use a screenshot test versus a semantics assertion in Compose?

Use semantics assertions for behavior like text presence, enabled state, or selection. Reserve screenshot tests for visual contracts semantics cannot prove: layout spacing, themed colors, typography, elevation, image composition, and focus highlight appearance.

Should Compose UI tests construct the full ViewModel and DI graph?

No. If the screen has a state holder/UI split, test the plain state-driven composable by passing a UiState and callbacks directly. Reserve integration tests with DI, navigation, and lifecycle for cases where that integration itself is the behavior under test.

Why are my Compose screenshot tests flaky?

Flakiness usually comes from nondeterministic state: live network images, current time, or running animations. Fake the image loader, freeze clocks and animation progress, and use fixed state data so every capture is identical.

When should I use test tags in Compose tests?

Use test tags only for nodes with no stable user-visible text or where multiple nodes share the same text. Prefer user-visible semantics like text, content description, and role first, since they assert what users actually perceive.