android-tdd

Guides test-driven development for Android and Kotlin Multiplatform code with tiered testing strategies.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/chmonya-inc/dnd-manager --skill android-tdd-chmonya-inc
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: android-tdd
Source: https://github.com/chmonya-inc/dnd-manager/tree/main/.agents/skills/android-tdd
Command: npx skills add https://github.com/chmonya-inc/dnd-manager --skill android-tdd-chmonya-inc

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable tests for Android and Kotlin Multiplatform code is hard: developers struggle to choose between unit, Robolectric, and instrumented tests, misuse mocks instead of fakes, and hit flaky coroutine or Compose UI tests. This Skill provides concrete patterns and anti-patterns for test-driven development in Android/KMP projects. ## Core Features & Use Cases - Three-Tier Test Selection: Choose between JVM unit tests, Robolectric integration tests, and instrumented tests based on what behavior is being proven. - Coroutine & Flow Testing: Use runTest, Turbine, MainDispatcherRule, and dispatcher injection to test suspend functions and StateFlow without hangs or races. - Compose UI & Screenshot Testing: Apply semantics-first node finders, callback-based assertions, and Roborazzi screenshot tests with deterministic state. - Use Case: When refactoring a LoginViewModel in a KMP app, follow the Given-When-Then template with a hand-written FakeAuthRepository and runTest to verify UI state transitions before writing production code. ## Quick Start Ask the AI to write a failing unit test for your Android ViewModel using fakes and runTest, following test-driven development.

Frequently Asked Questions about android-tdd

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

FAQPage Schema
How do I test a Kotlin coroutine ViewModel in Android?▼

Use runTest for all suspend functions and inject a CoroutineDispatcher into the ViewModel instead of hardcoding Dispatchers.Main. Replace Main with a MainDispatcherRule using StandardTestDispatcher, and pass the rule's dispatcher into runTest so both share one TestCoroutineScheduler.

Should I use mocks or fakes for Android unit tests?▼

Prefer hand-written fakes that implement the real interface with in-memory behavior over mocking frameworks like MockK. Fakes are reusable, readable, and test behavior rather than implementation. Use mocks only when verifying a specific interaction is the behavior under test, such as analytics events.

How do I test StateFlow in Kotlin without the test hanging?▼

Hot flows like StateFlow never complete, so collecting them directly on the TestScope hangs until the 60-second timeout. Use Turbine's test {} block, which collects and cancels automatically, or launch the collector on backgroundScope which is auto-cancelled at test end.

What is the difference between unit, Robolectric, and instrumented tests in Android?▼

Unit tests in src/test run on the JVM for pure logic like ViewModels and UseCases. Robolectric tests also run on the JVM but simulate Android for Room DAOs and Context-dependent code. Instrumented tests in src/androidTest run on a device or emulator for Compose UI and end-to-end flows.

Should Compose tests use testTag or semantics finders?▼

Prefer semantics-first finders like onNodeWithText and onNodeWithContentDescription because they assert what users actually see and exercise accessibility. Reserve onNodeWithTag for cases with no stable user-visible text, such as lists of identical rows or locale-dependent copy.

Why does my Compose animation test throw CancellationException?▼

The framework's InfiniteAnimationPolicy cancels indeterminate animations when the test clock auto-advances. Set mainClock.autoAdvance = false before setContent, then drive frames manually with advanceTimeByFrame() and advanceTimeBy(durationMillis).