compose-ui-testing-patterns
БесплатноБез исполняемых скриптовНе проверенUse when writing or reviewing Jetpack Compose UI tests, screenshot tests or baseline-recording evidence, previews, semantics assertions, fake image loading…
от chrisbanes★ 1 172 звезды на GitHubОб этом скилле
Compose: UI testing patterns
Core principle
Test the smallest UI contract that proves the behavior. Prefer plain state-driven UI tests with callbacks. Add integration only when lifecycle, navigation, DI, or platform behavior is the thing under test.
Procedure
- State the behavior and test concern the task asks you to prove.
- Inspect the existing test against that concern and choose the smallest sufficient seam from the table below.
- Keep focused edits within the requested test concern. Do not move test-only helpers into production or broaden production APIs unless that production boundary is itself under test.
- Drive controlled state or input, synchronize through Compose when needed, and assert an observable semantic, visual, or callback result.
- Finish with no edit when the existing test already uses the narrowest valid seam and proves the requested behavior.
Test target choice
| What you need to prove | Test shape |
|---|---|
| Text, buttons, conditional content, loading/error states, click/input callbacks | Plain UI Compose test |
| Focus navigation or keyboard behavior | Compose test with key input |
| Visual layout, clipping, elevation, typography, image composition | Screenshot test |
| State holder updates UI correctly | State holder/unit test plus one wiring smoke test |
| Hover, pressed, focused, dragged interaction state | Plain UI test with MutableInteractionSource |
| Navigation, lifecycle, DI integration | Integration test |
| Critical flow that depends on the installed build or crosses an app, process, or OS boundary | Focused device smoke test or end-to-end test, outside this skill |
Keep an existing cheaper regression for the contract it already proves.
For a real permission flow, retain the createComposeRule denied-state
assertion and add a device check for the Android dialog and the result the
OS delivers to the app. For R8-sensitive startup, retain the debug integration
test and add startup on the optimized artifact. StateRestorationTester
proves the local Compose save-and-restore round trip. Use an installed test
when actual activity callbacks, process death, or OS restoration are part
of the required behavior.
Plain UI and callback tests
Render the plain composable with controlled state and callbacks. Find nodes by
visible text or semantics. Use a tag when text is absent or ambiguous. Assert
enabled, selected, focused or toggled semantics directly, and use
assertDoesNotExist for absence. Capture callback arguments to prove wiring:
var selectedId: String? = null
composeTestRule.setContent {
ItemList(
items = listOf(ItemUi("movie-1", "Movie")),
onItemClick = { selectedId = it },
)
}
composeTestRule.onNodeWithText("Movie").performClick()
assertThat(selectedId).isEqualTo("movie-1")
Assert a plain captured value immediately after the action. Use runOnIdle
when the result depends on snapshot state, recomposition or queued work.
Use waitForIdle or a bounded waitUntil for a real asynchronous condition.
Leave clock auto-advance on unless testing a particular frame. With
mainClock.autoAdvance = false, advance to that frame once before its
assertions. Avoid Thread.sleep.
Interaction, keyboard and focus
For hover, press, focus or drag interaction state, read the interaction-state procedure before writing or reviewing the test. It uses direct, injected interactions.
For keyboard or D-pad navigation, send keys and assert focused semantics. If the composable has no input surface that can change the state, identify the missing host or parent before proposing a test. For focus graphs, restoration and key handlers, see focus navigation.
Screenshots and images
Use screenshots for visual contracts such as spacing, clipping, typography, image composition or focus highlights. Fix data, time and animation progress. Use a local painter or bitmap when appearance matters. When testing which image was requested, use a fake loader and assert the requested model.
When a named preset or default intentionally changes, keep it in the test and update its baseline. Keep an explicit fixed value when that geometry is the contract. Preserve assertions and tolerances unless a separate change justifies altering them.
For a recording claim, report three checks separately: the actual comparison result, whether recording wrote the exact output path declared by the test, and the observed baseline diff. Quote the reported comparison status and name the literal output path even when absent. A passing comparison can leave the artifact and baseline untouched. For a findings-only review, stop at missing evidence. Keep tool-specific commands in the repository runbook.
Установить compose-ui-testing-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл compose-ui-testing-patterns?
Use when writing or reviewing Jetpack Compose UI tests, screenshot tests or baseline-recording evidence, previews, semantics assertions, fake image loading, keyboard input, focus assertions, interaction state (hover/pressed/focused), or tests for plain state-driven UI composables.
Как установить скилл compose-ui-testing-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл compose-ui-testing-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic