testing-coroutines-with-runtest

testing-coroutines-with-runtest is a skill for Claude Code, Codex from skydoves/android-testing-skills. It costs 172 tokens per session (5,062 once invoked), scanned A, original, Apache-2.0.

A testing guide for Kotlin code that uses suspend functions and coroutines on the Java Virtual Machine. It covers controlled coroutine execution, virtual time, and testing code tied to Android's main thread.

In plain words
What is it for?
Use it to test ViewModels, lifecycle-aware classes, delayed coroutine work, and intermediate states such as Loading followed by Success.
Why use it?
It avoids slow or hanging tests caused by real delays and incorrect coroutine setup. It also helps replace the deprecated runBlockingTest approach and prevent main-thread dispatcher errors.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to test ViewModels, lifecycle-aware classes, delayed coroutine work, and intermediate states such as Loading followed by Success.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/skydoves/android-testing-skills/testing-coroutines-with-runtest
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add skydoves/android-testing-skills --skill testing-coroutines-with-runtest
Clone the repo
git clone --depth 1 https://github.com/skydoves/android-testing-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for testing-coroutines-with-runtest

README.md
[![agentmods](https://agentmods.dev/badge/skills/skydoves/android-testing-skills/testing-coroutines-with-runtest/github.svg)](https://agentmods.dev/skills/skydoves/android-testing-skills/testing-coroutines-with-runtest)
Your own site
<a href="https://agentmods.dev/skills/skydoves/android-testing-skills/testing-coroutines-with-runtest"><img src="https://agentmods.dev/badge/skills/skydoves/android-testing-skills/testing-coroutines-with-runtest/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for testing-coroutines-with-runtest

Your own site · 80×15
<a href="https://agentmods.dev/skills/skydoves/android-testing-skills/testing-coroutines-with-runtest"><img src="https://agentmods.dev/badge/skills/skydoves/android-testing-skills/testing-coroutines-with-runtest.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 172 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,062 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00172 $0.05062
Opus 5 $0.00086 $0.02531
Sonnet 5 $0.00034 $0.01012
Haiku 4.5 $0.00017 $0.00506

Measured 10d ago against content hash 4e26ba067ab6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

testing-coroutines-with-runtest scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 10d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

jvm-tests/coroutines/testing-coroutines-with-runtest/SKILL.md · 379 lines

How it starts

The opening of the file, as written. The whole thing — 379 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Testing Coroutines With runTest — Virtual Time Without Wall Clock

runTest is the only correct entry point for testing suspend functions and viewModelScope-backed code on the JVM. This skill nails down the TestScope contract, the two TestDispatcher flavors, the shared TestCoroutineScheduler virtual clock, and the MainDispatcherRule plumbing that keeps Dispatchers.setMain from leaking between tests. Flow-specific assertions live in ../testing-flows-with-turbine/SKILL.md.

When to use this skill

  • The class under test exposes a suspend fun or launches into viewModelScope / lifecycleScope.
  • The developer reaches for runBlocking { … } and the test hangs, or a 10-minute delay makes the test slow.
  • A ViewModel emits Loading -> Success from a coroutine and the test needs to assert each intermediate state.
  • The build emits the deprecation runBlockingTest is deprecated. Use runTest or runTest(... dispatchTimeoutMs = ...) errors.
  • The test fails with IllegalStateException: Module with the Main dispatcher is missing because viewModelScope routed work through Dispatchers.Main.
  • The developer needs to advance virtual time (advanceTimeBy(5.seconds), advanceUntilIdle()) to trigger a timeout / retry / debounce.

When NOT to use this skill

  • The test asserts Flow emissions across time. Use ../testing-flows-with-turbine/SKILL.md (Turbine handles cancellation, hot vs cold, awaitItem/awaitComplete).
  • The test exercises Compose's MainTestClock rather than kotlinx.coroutines.test. Use ../../../compose/synchronization/controlling-the-test-clock/SKILL.md.
  • The test runs on an emulator/device through AndroidJUnit4. JUnit4 setup itself is ../../runner/configuring-junit4-on-android/SKILL.md.

Prerequisites

  • Gradle: testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.x") (docs/CORPUS.md §G.1). MUST be testImplementation only — never implementation. The library installs Dispatchers.setMain plumbing that is unsafe to ship to production.
  • @file:OptIn(ExperimentalCoroutinesApi::class) (or per-call) on test files. currentTime, advanceTimeBy, advanceUntilIdle, runCurrent, and the dispatcher constructors are still @ExperimentalCoroutinesApi on 1.10.x (R5).
  • For ViewModel tests, an injected CoroutineDispatcher (a "DispatcherProvider") so the SUT can route work onto the same TestCoroutineScheduler the test body advances. Hard-coded Dispatchers.IO / Dispatchers.Default will NOT see virtual time.
  • For KMP libraries that compile to JS / wasm, use the single-expression form fun foo() = runTest { … } so the platform TestResult is returned (R5; see "TestResult contract" below).

Read the full file on GitHub · 379 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 10d ago First seen · 379 lines · 172 tokens per session scan A 4e26ba067ab6

Subscribe to this mod's changes

testing-coroutines-with-runtest is a skill published in the GitHub repository skydoves/android-testing-skills (319 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 172 tokens to every session and 5,062 once invoked, about $0.0009 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories