Testing
1. Why
A design-system library breaks in visual and behavioral ways that ordinary unit tests don't see:
- a renderer that stops applying the behavior modifier;
- a token no longer honored;
- a dark-mode contrast regression;
- a layout that clips at 200% font scale.
This note defines the test layers and the matrix every component goes through. The per-component tests are listed in each component note's build steps (starting at Components — Overview). The contract being tested is Skin Contract.
2. Shape
| Layer | Where it runs | Tool |
|---|---|---|
| Unit | every target (jvm, iOS simulator, wasmJs, android host) | kotlin.test |
| Component | jvm (fast, CI default), iOS simulator; android host via Robolectric | Compose Multiplatform runComposeUiTest (common UI-test API) |
| Screenshot | android host (Robolectric), jvm desktop; iOS (experimental) | Roborazzi |
| Accessibility | Android and iOS, manually + with automated checks where available | TalkBack/VoiceOver checklist; automated Accessibility Test Framework checks on Android through Compose ui-test's enableAccessibilityChecks() |
No screenshot or a11y testing on web: Roborazzi doesn't support it, and the canvas limits screen readers (ADR-18). Web gets unit + component tests where runComposeUiTest runs.
3. API
3.1 Shared test utilities (in commonTest, possibly a camouflage-skin-testing artifact later)
fun ComposeUiTest.setCamoContent(skin: CamoSkin = MinimalSkin, theme: CamoTheme = minimalLight,
fontScale: Float = 1f, rtl: Boolean = false, content: @Composable () -> Unit)
fun ComposeUiTest.assertRendererAppliesBehavior(renderClickable: @Composable (onClick: () -> Unit) -> Unit)
// clicks at the node's corner and its center, and expects both to fire; expects a semantics role
fun <S> assertNoLiterals(render: @Composable (style: S) -> Unit, oddStyle: S, measure: (SemanticsNode) -> Boolean)
3.2 The screenshot matrix
| Axis | Values |
|---|---|
| skin | MinimalSkin (+ DebugSkin for contract tests) |
| theme | minimalLight, minimalDark on every axis; one brand theme (from fromSeed, with a custom token set) from M3, but only in one combination per component: light, font 1.0, LTR |
| font scale | 1.0, 2.0 |
| direction | LTR, RTL |
| component states | per component: variants × tones × enabled/disabled/focused/pressed(where capturable) |
The file naming is button_primary-error_material_dark_fs2_rtl.png. Goldens live in src/<target>Test/snapshots, and CI runs verifyRoborazzi*. Goldens render with the Ahem test font (CamoTheme.withGoldenFont() in camouflage-skin-testing, as Flutter's CI goldens do), which keeps them close across OSes; the text boxes' edges still antialias differently on macOS and Linux, so the goldens are Linux renders (CI's own, from the PR's roborazzi-outputs artifact, which CI uploads whenever a golden differs) and verify within 0.5% of the pixels. Since M3 the JVM desktop goldens run on every PR; Android (Robolectric) and iOS join with the full matrix in M9. Compose UI tests live in skikoTest (JVM, iOS, wasmJs); on the Android host they'd need Robolectric. Record with recordRoborazzi* locally, and review the diffs in the PR.
3.3 Coverage
Kover on core logic (theme, rules, filters and formats, form state, provider): ≥ 75% lines, enforced in check from M2. Renderers are covered by screenshots, not line coverage.
4. Build steps
setCamoContentand the assertion utilities.- Unit tests per the base notes' build steps (already listed in each Kotlin note).
- Roborazzi setup: the plugin in
com.srctool.kmp.library, Robolectric@GraphicsMode(NATIVE)for the android host, the desktop capture for jvm. - The matrix generator: a parameterized test per component that iterates the axes.
- The CI jobs:
verifyRoborazziDebug(android host) +verifyRoborazziJvminjvm-and-android, and iOS verification in theiosjob (allowed to fail while experimental). - The accessibility checklist per milestone (TalkBack + VoiceOver): every interactive element reachable, correctly named, role and state announced; errors announced.
Done when
-
./gradlew checkruns unit + component + screenshot verification on jvm and android. - A deliberately broken renderer (behavior modifier removed) fails
assertRendererAppliesBehavior. - A deliberately hard-coded height fails the no-literals test.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Font rendering differs by platform | Goldens are per target. Never compare android goldens to desktop goldens. |
| Animations in screenshots | Capture with mainClock.autoAdvance = false and advance to the end state. Reduced motion in tests also removes flakiness. |
| Flaky iOS screenshot support | Allowed to fail in CI until Roborazzi's iOS support leaves experimental. |
| Web | Unit and component tests only. |
Already in place (built with the milestones): camouflage-skin-testing (assertRendererAppliesBehavior, assertNoLiterals, the galleries, the golden font), unit, component (skikoTest) and Roborazzi JVM goldens for all five skins (light, dark, brand; Linux renders from CI), Kover, ABI, Detekt and the layer check in check, and CI on JVM, Android, iOS simulator and wasm.
Left for M15:
- The matrix axes the milestones skipped: font scale 2.0 and RTL for every skin's galleries (today only a few components have them), and one brand theme per skin (done for four, Carbon has it).
- Accessibility: Compose's
enableAccessibilityChecks()on the Android host over every gallery, and the TalkBack and VoiceOver checklist per component family, run by hand on the Galaxy A15 and the iPhone (the results go in this note). - Android host goldens (Robolectric) and iOS goldens: still allowed to fail while Roborazzi's support is experimental; decide whether v0.1 ships without them.
- The two "deliberately broken" checks of Done when, as permanent tests (a renderer without the behavior modifier, a hard-coded height) so the guards are proven to bite. Open for review: whether Android host goldens are required for v0.1 (they triple the golden count); whether the 200% font scale axis runs on every gallery or on a representative set per family.
- Decided: Android host and iOS goldens are required for v0.1 (not built yet); the 200% text and RTL axes run on a representative set of twelve galleries per skin (buttons, icon buttons, inputs, text inputs, structure, data display, navigation, navigation chrome, actions, small data, lists, collections), not on all eighteen;
camouflage-skin-testingis published; the group id stayscom.srctool.camouflage. - Built:
accessibilityProblemsincamouflage-skin-testing(every clickable node has a name, a role or state, and a 44 dp touch target; parts scrolled out of a row or column are not measured along the scroll axis), and a*AccessibilityTestin each skin over those galleries: light, dark, 200% text and right to left. The two "deliberately broken" guards of Done when already exist asSelfTest. - Found and fixed in core: the tree's expand chevron had no name (it now says "Expand" or "Collapse"); a navigation item whose label is not drawn (the Carbon and Fluent rail, Never labels) had no name for a screen reader (it now carries its label as a description); the gallery's bare checkboxes were unnamed (named without changing how they look).
- Not done: the by-hand TalkBack and VoiceOver pass; Android's
enableAccessibilityChecks()(needs the Android host test setup, which comes with the Android host goldens).
Done by hand on the sample app (release build) on an Android phone (Samsung SM A156E, Android 16, TalkBack) and an iPhone (iPhone 17 Pro, iOS 27.2, VoiceOver). Everything passed except one finding: text fields had no accessible name. VoiceOver said "text field" only, and TalkBack could name only the date field and a disabled field (an uiautomator dump showed each editable node with empty text, no description and NAF=true). The cause: namedBy() put the label in a 0 × 0 node inside the field, and the label never reached the editable node.
Fix: CamoTextField and CamoSearchField now set the name as the editable node's contentDescription (the typed text stays separate). Re-checked by hand on both devices: the name and the typed text are both announced. A JVM test (theEditableNodeCarriesTheLabelAsItsNameAndKeepsWhatIsTyped) keeps it from regressing. The same pass on Flutter found nothing.
Also checked by hand (#148): Reduce Transparency toggled while the app was open takes effect live on an iPhone 17 Pro, and a 30 s scroll that opens a popup and a dialog felt smooth (not measured with Instruments). Not checked: the Android 12 blur (no such device) and the web refraction edge by eye.
Not covered: the by-skin, by-step breakdown of the screen reader pass was not itemised.