compose-test-generator
Generate Compose UI tests for Android and Kotlin Multiplatform projects. Use when: (1) Writing tests for @Composable functions, (2) Creating screenshot/snapshot tests, (3) Testing state changes and user interactions in Compose UI, (4) Adding test coverage to screens. Triggers: "compose test", "ui test", "write tests for", "test this composable", "screenshot test", "paparazzi", "roborazzi", "compose testing".
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
Compose Test Generator
Generate idiomatic Compose UI tests following best practices.
Coding Standards
MANDATORY: This skill follows kotlin-compose-standards. All generated code MUST comply with these standards:
- Trailing comma EXCEPT for Modifier arguments
- Parameter order: required → Modifier → optional
- Modifier passed last when calling composables
- Each Modifier method on its own line
- New line at end of file
Quick Start
class MyComponentTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun component_displaysCorrectly() {
composeTestRule.setContent {
MyComponent(text = "Hello")
}
composeTestRule.onNodeWithText("Hello").assertIsDisplayed()
}
}
Workflow
- Read the composable to understand structure and state
- Identify test scenarios: happy path, edge cases, interactions
- Choose test type: behavior test, screenshot test, or both
- Generate test file in appropriate location
- Add test tags to composable if needed for reliable selection
References
| File | When to Read |
|---|---|
| selectors.md | Finding nodes, test tags, semantic matchers |
| actions.md | Click, type, scroll, gesture actions |
| assertions.md | Visibility, state, content assertions |
| screenshot-tests.md | Paparazzi, Roborazzi setup and usage |
Test Patterns
Stateless Component Test
@Test
fun button_showsLabel() {
composeTestRule.setContent {
PrimaryButton(label = "Submit", onClick = {})
}
composeTestRule.onNodeWithText("Submit").assertIsDisplayed()
}
Stateful Interaction Test
@Test
fun counter_incrementsOnClick() {
composeTestRule.setContent {
CounterScreen()
}
composeTestRule.onNodeWithText("0").assertIsDisplayed()
composeTestRule.onNodeWithTag("increment_button").performClick()
composeTestRule.onNodeWithText("1").assertIsDisplayed()
}
ViewModel Integration Test
@Test
fun screen_showsLoadedData() = runTest {
val viewModel = MyViewModel(FakeRepository())
composeTestRule.setContent {
MyScreen(viewModel = viewModel)
}
composeTestRule.waitUntil {
composeTestRule.onAllNodesWithTag("item")
.fetchSemanticsNodes().isNotEmpty()
}
composeTestRule.onAllNodesWithTag("item").assertCountEquals(3)
}
Output Location
Place test files following project convention:
- Android:
app/src/androidTest/java/.../orapp/src/test/java/.../ - KMP:
shared/src/commonTest/kotlin/.../ - Screenshot tests: Usually in
src/test/(JVM-based)
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!