Skip to Content
CrowCrow

Headless UI Testing (crow-ui-test)

Fast, deterministic JVM UI tests with real text shaping, scripted gestures, semantics tree dumps, and PNG visual snapshots — no emulator required.

crow-ui-test runs your real Crow UI tree and CrowView headlessly on the JVM via Robolectric — giving you millisecond feedback loops, deterministic frame stepping, gesture replay, semantics assertions, and pixel-accurate PNG snapshots with zero emulator flakiness.

Writing a Headless UI Test

CounterScreenTest.kt
@RunWith(RobolectricTestRunner::class)
class CounterScreenTest {
    @Test
    fun tappingAddIncrementsCountAndUpdatesSemantics() {
        headless {
            MaterialTheme { CounterScreen() }
        }.use { app ->
            // Advance deterministically until initial layout & animations settle
            app.settle()
            assertTrue(app.dump().contains("Count: 0"))

            // Tap by text or semantics label
            app.tap("Add 1")
            app.frame()

            assertTrue(app.dump().contains("Count: 1"))
            assertTrue(app.dump().contains("Next tap reaches 2"))
        }
    }
}

Capabilities

  • Deterministic motion clock: Call app.frame() to step a single frame (16 ms default) or app.settle() to advance analytic springs, exit ghosts, and pending transitions cleanly without Thread.sleep.
  • Scripted input: Replay tap, drag, fling, type, imeAction, hardware key, resize, and back against real hit-testing and gesture recognizers.
  • Semantics & layout tree dumps: app.dump() prints node kinds, bounds, text content, and TalkBack semantics roles/states for crisp structural assertions.
  • Real PNG snapshots: Call app.png(File(...)) to render any screen or overlay state to a PNG with real Skia/Minikin text shaping — ideal for visual diffs, CI artifacts, and AI-assisted UI verification.
  • Headless CLI rendering: Render any demo screen straight to PNG and a tree dump with:
gradle :benchmarks:e1:headlessRender -Pscreen=gallery

Testing Reactive Core & Queries on Pure JVM

Because crow-signals, crow-runtime, crow-router, crow-image, crow-query, crow-store, crow-state, crow-schema, crow-color, crow-motion, and crow-inject are 100% pure JVM (checkCorePurity), unit tests for business logic, state graphs, forms, persistence, and caching run on plain JVM with zero Android runtime overhead.

How is this guide?

On this page