
compose-test-generator
by shoheikawano
SKILL.md
name: compose-test-generator description: | 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". context: fork agent: general-purpose user-invocable: true allowed-tools:
- Read
- Write
- Edit
- Glob
- Grep
- Bash
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)
Score
Total Score
Based on repository quality metrics
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
Reviews
Reviews coming soon