testing-coroutines-with-runtest
CommunityTest suspend code with virtual time.
System Documentation
What problem does it solve?
This Skill helps you reliably test suspend functions and coroutine-driven classes on the JVM without real-time delays, flakiness, or tests hanging due to incorrect coroutine test setup.
Core Features & Use Cases
- Correct entry point with virtual time: Uses
runTestwithTestScopeand virtual clock control viaTestCoroutineScheduler. - Dispatcher correctness for stateful code: Explains
StandardTestDispatchervsUnconfinedTestDispatcher, and howDispatchers.setMainprevents missing-main-dispatcher crashes inviewModelScopetests. - Flow-collector safety: Covers the common hang scenario when collecting hot flows directly in
TestScope, steering you tobackgroundScopeor the sibling Turbine skill. - KMP correctness note: Describes the
TestResultcontract and why single-expression@Test fun foo() = runTest { ... }matters for Kotlin/JS and wasm targets.
Real-world example: testing a ViewModel that emits Loading -> Success from a coroutine where you need to advance virtual time (advanceUntilIdle or advanceTimeBy) to deterministically assert intermediate states.
Quick Start
Use the testing-coroutines-with-runtest skill when you need to write a JVM runTest for a viewModelScope-backed suspend flow that currently hangs or is timing out in CI.
Dependency Matrix
Required Modules
None requiredComponents
💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: testing-coroutines-with-runtest Download link: https://github.com/skydoves/android-testing-skills/archive/main.zip#testing-coroutines-with-runtest Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.