choosing-test-rule-vs-runtest

Select the correct Jetpack Compose UI test entry point between TestRule and runComposeUiTest APIs.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill prevents Compose UI tests from failing or behaving inconsistently by helping you choose the correct test entry point and avoiding forbidden mixes of environments.

Core Features & Use Cases

  • Choose the correct Compose UI test entry point: decide between JUnit4 createComposeRule()/createAndroidComposeRule<A>()/createEmptyComposeRule() and the suspending runComposeUiTest { }/runAndroidComposeUiTest<A> { }/runEmptyComposeUiTest { } APIs.
  • Avoid common breaking patterns: ensure you do not mix the rule-based ComposeTestRule environment with the lambda-based ComposeUiTest environment in the same test.
  • Fix setContent and activity-launch edge cases: call setContent exactly once per test (and never call it via the rule when the launched Activity already sets Compose content).
  • Prefer v2 for new code: select the v2 imports that use StandardTestDispatcher to match coroutine scheduling expectations, and address v1-to-v2 behavior changes.

Quick Start

Use this skill to map your intended test setup to the correct Compose UI testing API and confirm the right v2 imports and constraints for setContent and environment mixing.

Frequently Asked Questions about choosing-test-rule-vs-runtest

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

FAQPage Schema
When should I use runComposeUiTest instead of createComposeRule in Jetpack Compose UI tests?

Use runComposeUiTest for suspending Compose Multiplatform tests or custom coroutine scheduling, while createComposeRule fits JUnit4 Android-only tests. This skill resolves which Compose UI test entry point matches your target platform and coroutine dispatcher needs.

How do I fix inconsistent Jetpack Compose UI test behavior with StandardTestDispatcher?

Fix inconsistent Compose UI test behavior by migrating to v2 API imports that use StandardTestDispatcher for deterministic coroutine scheduling. This skill helps select the correct v2 imports and addresses v1-to-v2 behavior changes.

Can I mix ComposeTestRule and runComposeUiTest in the same Jetpack Compose UI test?

You cannot mix the rule-based ComposeTestRule environment with the lambda-based ComposeUiTest environment in the same Compose UI test. This skill identifies these breaking patterns and ensures you use a single environment per test.

How many times can I call setContent in a Jetpack Compose UI test?

You can call setContent exactly once per Compose UI test, and never via the rule if the launched Activity already sets Compose content. This skill validates these activity-launch and setContent edge cases.

Does Compose Multiplatform support runAndroidComposeUiTest for UI testing?

Compose Multiplatform uses runComposeUiTest or runEmptyComposeUiTest for UI testing, whereas runAndroidComposeUiTest targets Android-only scenarios. This skill maps your test setup to the correct cross-platform or Android-specific API.

What is the effectContext parameter used for in Compose UI tests?

The effectContext parameter enables custom coroutine scheduling in Compose UI tests by configuring the test dispatcher. This skill determines when your scenario requires effectContext and selects the appropriate v2 API entry point.