setting-up-host-vs-device-tests

Select host or device source sets for Jetpack Compose UI tests.

303|10|Updated May 15, 2026
One-click install
npx skills add https://github.com/skydoves/android-testing-skills --skill setting-up-host-vs-device-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: setting-up-host-vs-device-tests
Source: https://github.com/skydoves/android-testing-skills/tree/main/compose/setup/setting-up-host-vs-device-tests
Command: npx skills add https://github.com/skydoves/android-testing-skills --skill setting-up-host-vs-device-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you decide whether a Jetpack Compose test should run on the host (Robolectric/JVM) or on a real/virtual device (instrumentation), and then configure it so key capabilities actually work.

Core Features & Use Cases

  • Host vs device selection: Use src/test/ (host) for fast logic/recomposition/finder-style assertions, and src/androidTest/ (device) for RenderThread-dependent behavior.
  • Correct source-set placement: Organize tests so screenshot capture, ripple/Modifier.indication rendering, and accessibility checks run in the right flavor.
  • Robolectric host skeleton & guardrails: Apply the canonical @RunWith(AndroidJUnit4::class) and @Config(minSdk = 23) setup and enforce clock-driven determinism.
  • Legitimate Thread.sleep only for RenderThread: Replace Thread.sleep in host tests entirely, and allow it in device tests only as a RenderThread waiting mechanism for screenshot/golden assertions.

Quick Start

Tell the AI: “I have a Jetpack Compose test that passes locally but fails on CI—should it go in src/test or src/androidTest, and what setup do I need?”

Frequently Asked Questions about setting-up-host-vs-device-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between Robolectric and instrumentation tests for Jetpack Compose?

Use src/test (host) with Robolectric for fast logic and finder-style assertions, and src/androidTest (device) for RenderThread-dependent behaviors like screenshots, ripples, and accessibility checks.

Why does my Compose screenshot test fail when using Robolectric?

Compose screenshot tests fail under Robolectric if placed in the wrong source set or lacking @Config(minSdk = 23). Move RenderThread-dependent screenshot and ripple rendering to androidTest.

What is the correct way to handle timing in Jetpack Compose UI tests?

Drive deterministic Compose UI test timing using mainClock.advanceTimeBy. Restrict Thread.sleep exclusively to device tests for waiting on the RenderThread during screenshot or ripple assertions.

Can I use Thread.sleep in Compose host tests for animations?

No, replace Thread.sleep entirely in host tests with mainClock.advanceTimeBy for deterministic animation and gesture timing. Only use Thread.sleep in device tests for RenderThread-dependent screenshot waiting.

Do I need @Config for Jetpack Compose Robolectric tests?

Yes, canonical Compose Robolectric tests require the @RunWith(AndroidJUnit4::class) and @Config(minSdk = 23) setup to enforce proper execution environments and clock-driven determinism.

When should Compose accessibility checks run on device versus host?

Compose accessibility checks should run in the src/androidTest device source set alongside other RenderThread-dependent behaviors like indication rendering and screenshot capture.