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
runTest with TestScope and virtual clock control via TestCoroutineScheduler.
- Dispatcher correctness for stateful code: Explains
StandardTestDispatcher vs UnconfinedTestDispatcher, and how Dispatchers.setMain prevents missing-main-dispatcher crashes in viewModelScope tests.
- Flow-collector safety: Covers the common hang scenario when collecting hot flows directly in
TestScope, steering you to backgroundScope or the sibling Turbine skill.
- KMP correctness note: Describes the
TestResult contract 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.