structuring-a-compose-test

Standardize Jetpack Compose UI test architecture with single test rules and state hoisting.

Updated Jul 20, 2026
One-click install
npx skills add https://github.com/trancee/MeshLink-template --skill structuring-a-compose-test-trancee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: structuring-a-compose-test
Source: https://github.com/trancee/MeshLink-template/tree/main/.agents/skills/android-testing-skills/compose/patterns/structuring-a-compose-test
Command: npx skills add https://github.com/trancee/MeshLink-template --skill structuring-a-compose-test-trancee

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill resolves common Jetpack Compose testing issues such as flaky tests, race conditions, and compilation errors caused by improper test class structure, incorrect state hoisting, and mismanaged test rules.

Core Features & Use Cases

  • Canonical Class Skeleton: Provides the exact structure used by androidx libraries, including proper rule declaration and test method organization.
  • State Management: Guides the user on how to correctly hoist mutable state above setContent to allow external driving of UI state.
  • Lifecycle Best Practices: Prevents common pitfalls like calling setContent in @Before or mixing incompatible test entry points.

Quick Start

Ask the assistant to generate a standard Jetpack Compose test class skeleton that follows the androidx canonical pattern for a specific UI component.

Frequently Asked Questions about structuring-a-compose-test

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

FAQPage Schema
Why are my Jetpack Compose UI tests flaky and prone to race conditions?

Flaky Compose UI tests often stem from improper state hoisting and mismanaged test rules. Standardizing your test architecture with a single test rule and correct lifecycle management prevents race conditions during UI verification.

How do I structure a Jetpack Compose UI test class to avoid compilation errors?

To structure a Compose UI test class, use the canonical androidx skeleton with a single test rule declaration. Avoid calling setContent in @Before and ensure proper test method organization to prevent compilation errors.

What is the correct way to hoist state in Jetpack Compose instrumentation tests?

Correct state hoisting in Compose instrumentation tests involves lifting mutable state above setContent. This allows external driving of UI state, ensuring reliable state mutation and observation within the Compose environment.

What is the Test-Find-Assert-Act-Re-assert flow in Jetpack Compose testing?

The Test-Find-Assert-Act-Re-assert flow is a standardized sequence for Compose UI testing. It enforces finding UI elements, asserting initial state, acting on the UI, and re-asserting to verify reliable state mutation and observation.

Does Jetpack Compose testing require a specific test rule entry point for AndroidJUnit4?

Yes, Compose instrumentation tests require a single v2 test rule entry point for AndroidJUnit4. Mixing incompatible test entry points leads to lifecycle mismanagement and flaky UI verification.

Can I call setContent in the @Before method for Jetpack Compose UI tests?

No, calling setContent in @Before is a common pitfall in Compose testing. You should use the canonical class skeleton and proper lifecycle best practices to avoid mismanaged test rules and compilation errors.