搜索

PythonReactSEOPDF
GitHub Skill

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".

shoheikawano☆ 3 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

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

  1. Read the composable to understand structure and state
  2. Identify test scenarios: happy path, edge cases, interactions
  3. Choose test type: behavior test, screenshot test, or both
  4. Generate test file in appropriate location
  5. 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/.../ or app/src/test/java/.../
  • KMP: shared/src/commonTest/kotlin/.../
  • Screenshot tests: Usually in src/test/ (JVM-based)

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!