testing-coroutines-with-runtest

Community

Test suspend code with virtual time.

Authorskydoves
Version1.0.0
Installs0

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 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.

Dependency Matrix

Required Modules

None required

Components

references

💻 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.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.