choosing-test-rule-vs-runtest
Installation
SKILL.md
Choosing Test Rule vs runComposeUiTest — One Entry Point Per Test
Compose ships two parallel test entry points: a JUnit4 TestRule (createComposeRule() and friends) and a multiplatform suspending lambda (runComposeUiTest { }). Each one independently sets up the recomposer, MainTestClock, and IdlingResource. Mixing them in a single test produces double-environment bugs that are hard to diagnose. This skill picks the right one and surfaces the v1 → v2 deprecation that bites every existing codebase.
When to use this skill
- The user is starting a new Compose UI test and is choosing between
createComposeRule()andrunComposeUiTest { }. - The IDE shows a deprecation
WARNINGonimport androidx.compose.ui.test.junit4.createComposeRuleorimport androidx.compose.ui.test.runComposeUiTest. - The user reports tests passing on v1 entry points but breaking after migrating because
LaunchedEffects no longer run synchronously. - The user has a custom
ComponentActivitysubclass and is unsure betweencreateAndroidComposeRuleandcreateEmptyComposeRule. - The user reports
IllegalStateException: setContent can only be called once per ComposeTestRuleor "the launched Activity already calls setContent". - The user is writing Compose Multiplatform (KMP) tests and needs the suspending entry point.
When NOT to use this skill
- The dependencies do not yet compile — start with
./configuring-test-dependencies/SKILL.md. - The choice is host vs device, not rule vs lambda — see
./setting-up-host-vs-device-tests/SKILL.md. - The test compiles and runs but flakes on idle/animation — see
../../synchronization/synchronizing-with-idle/SKILL.mdand../../synchronization/testing-animations-deterministically/SKILL.md.