Agent skill

Android Coroutine Testing

by timusus in timusus/Shuttle2

Comprehensive guidance for writing deterministic tests for Android code using Kotlin coroutines.

Apache-2.0Auto-check passedMobile

Install Android Coroutine Testing

skills CLI
$ npx skills add timusus/Shuttle2 --skill android-coroutine-testing -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install timusus/Shuttle2 android-coroutine-testing --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/timusus/Shuttle2.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/android-coroutine-testing .claude/skills/android-coroutine-testing && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
android-coroutine-testing
GitHub stars
229
Token cost
~1.2k tokens
SKILL.md length
325 words
Files
1
Skills in repo
13
Repo updated
First seen
Licence
Apache-2.0

At a glance

Comprehensive guidance for writing deterministic tests for Android code using Kotlin coroutines.

  • Works in 5 steps: One scheduler per test - Share scheduler… → Inject dispatchers - Never use… → Use runTest - One invocation per test… → …
  • Testing suspending functions
  • SKILL.md covers Quick Start, Key Concepts, Working with Scopes and Time Control, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Android Coroutine Testing is an agent skill from timusus/Shuttle2. Comprehensive guidance for writing deterministic tests for Android code using Kotlin coroutines. Use when testing suspending functions, coroutines, flows, ViewModels with coroutines, or when needing to handle test dispatchers, runTest, backgroundScope, testScope, or virtual time control.

Its SKILL.md is about 1.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile. It works with Android and Kotlin. The repository describes itself as: Shuttle Music: a music player for Android and iOS. Plays local files and streams from Jellyfin, Emby, Plex and Navidrome/Subsonic, with Chromecast, Android Auto, EQ and replay… The licence is Apache-2.0.

When your agent uses it

  • Testing suspending functions
  • ViewModels with coroutines
  • Needing to handle test dispatchers
  • BackgroundScope

Example prompts

  • “/android-coroutine-testing”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. One scheduler per test - Share scheduler between all test dispatchers
  2. Inject dispatchers - Never use Dispatchers.IO or Dispatchers.Default directly
  3. Use runTest - One invocation per test method
  4. Clean up flows - Cancel infinite flow collections
  5. Avoid real delays - Use virtual time instead

What it can do on your machine

Read from SKILL.md and the folder at commit 9cef5dd. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are kotlin).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Android Coroutine Testing loads about 1.2k tokens when it runs. Until then it costs about 79 tokens; SKILL.md has 325 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~79
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from timusus/Shuttle2 at commit 9cef5dd, republished under its Apache-2.0 licence (© timusus). 325 words, ~1,165 tokens.

Download SKILL.mdSave it as .claude/skills/android-coroutine-testing/SKILL.md (or your agent's skills folder).
name
android-coroutine-testing
description
Comprehensive guidance for writing deterministic tests for Android code using Kotlin coroutines. Use when testing suspending functions, coroutines, flows, ViewModels with coroutines, or when needing to handle test dispatchers, runTest, backgroundScope, testScope, or virtual time control.

Android Coroutine Testing

Write deterministic tests for coroutine-based Android code using runTest, test dispatchers, and proper scope management.

Quick Start

Basic Setup

The kotlinx-coroutines-test dependency (version 1.10.2, see gradle/libs.versions.toml) is already on the test classpath via libs.kotlinx.coroutinesTest.

Essential Testing Pattern
kotlin
@Test
fun myCoroutineTest() = runTest {
    // Arrange
    val testDispatcher = StandardTestDispatcher(testScheduler)
    val repository = MyRepository(testDispatcher)

    // Act
    val result = repository.fetchData()

    // Assert
    assertEquals("expected", result)
}

Key Concepts

runTest
  • Wraps test code that calls suspending functions
  • Automatically skips delays (uses virtual time)
  • Waits for coroutines on test dispatchers to complete
  • Use expression body syntax: = runTest { ... }
Test Dispatchers

StandardTestDispatcher (default)

  • Queues new coroutines
  • Requires manual time advancement
  • Use advanceUntilIdle() to run pending work
  • Best for testing precise execution order

UnconfinedTestDispatcher

  • Executes coroutines eagerly/immediately
  • Simpler tests but different from production behavior
  • Use when execution order doesn't matter
Dispatcher Injection

Always inject dispatchers for testability:

kotlin
// Bad - Hardcoded dispatcher
class Repository {
    suspend fun fetchData() = withContext(Dispatchers.IO) { ... }
}

// Good - Injectable dispatcher
class Repository(
    private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
) {
    suspend fun fetchData() = withContext(ioDispatcher) { ... }
}
Main Dispatcher

Replace the Main dispatcher using the repo's existing rule at android/app/src/test/java/com/simplecityapps/testing/MainDispatcherRule.kt:

kotlin
@get:Rule
val mainDispatcherRule = MainDispatcherRule()

@Test
fun viewModelTest() = runTest {
    val viewModel = MyViewModel()
    viewModel.loadData() // Uses test Main dispatcher
    assertEquals(expected, viewModel.state.value)
}

It defaults to UnconfinedTestDispatcher; pass a StandardTestDispatcher(testScheduler) if a test needs precise execution order instead.

Working with Scopes

TestScope Usage
kotlin
@Test
fun testWithBackgroundWork() = runTest {
    // Use backgroundScope for work that outlives the test body
    backgroundScope.launch {
        // Long-running collection
        repository.dataFlow.collect { ... }
    }

    // Test body completes, but waits for backgroundScope
    repository.updateData("new")
    advanceUntilIdle()
}
Injecting Scopes
kotlin
class MyClass(private val scope: CoroutineScope) {
    fun startWork() {
        scope.launch { ... }
    }
}

@Test
fun scopeInjectionTest() = runTest {
    val myClass = MyClass(scope = this) // Pass TestScope
    myClass.startWork()
    advanceUntilIdle()
}

Time Control

Control virtual time in tests:

  • advanceUntilIdle() - Run all pending coroutines
  • advanceTimeBy(millis) - Advance time and run scheduled work
  • runCurrent() - Run coroutines at current time only
  • testScheduler.currentTime - Check current virtual time

Exception Handling

kotlinx-coroutines-test surfaces uncaught exceptions from backgroundScope and other test dispatchers by failing the runTest block directly — no separate exception-handler utility is needed. Assert with a standard assertThrows / try/catch around the failing call instead.

Best Practices

  1. One scheduler per test - Share scheduler between all test dispatchers
  2. Inject dispatchers - Never use Dispatchers.IO or Dispatchers.Default directly
  3. Use runTest - One invocation per test method
  4. Clean up flows - Cancel infinite flow collections
  5. Avoid real delays - Use virtual time instead

Flow Testing

This repo does not depend on Turbine. Test Flow emissions by collecting into a list inside runTest (e.g. via backgroundScope.launch { flow.toList(results) } or flow.first()/flow.take(n).toList()) and asserting on the collected values.

Mocking

MockK (libs.mockk) is on the test classpath if a mock is genuinely needed. Prefer a real fake implementation over a mock where the collaborator is simple (e.g. an in-memory repository).

© timusus, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/android-coroutine-testing of timusus/Shuttle2.

Open the folder on GitHubat commit 9cef5dd

Compare with similar skills

Android Coroutine Testing next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Android Coroutine Testing compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Android Coroutine Testing this skilltimusus/Shuttle2229—~1.2kAutomated safety check: PassApache-2.0
Android Hidden API and R8 Checkgkd-kit/gkd43k—~1.5kAutomated safety check: PassGPL-3.0
Compose Multiplatform Patternsmonta-app/ocpp-emulator1805 repos~2kAutomated safety check: PassApache-2.0
Android Developmentdpconde/claude-android-skill336—~1.7kAutomated safety check: PassMIT
Ha Android Architecturehome-assistant/android4k—~1.7kAutomated safety check: PassApache-2.0
Architecture Overclocknekomangaorg/Neko2.8k—~1.4kAutomated safety check: PassApache-2.0

Similar skills

  • Checks whether Android hidden-API implementations and system callbacks survive R8 minification, and diagnoses Release-only failures such as AbstractMethodError.

    43k GitHub stars~1.5k tokensUpdated yesterday
    MobileAuto-check passed
  • Compose Multiplatform Patterns

    monta-app/ocpp-emulator

    Compose Multiplatform and Jetpack Compose patterns for KMP projects — state management, navigation, theming, performance, and platform-specific UI.

    180 GitHub starsUsed in 5 repos~2k tokens
    MobileAuto-check passed
  • Android Development

    dpconde/claude-android-skill

    Create production-quality Android applications following Google's official architecture guidance and NowInAndroid best practices.

    336 GitHub stars~1.7k tokensUpdated 10 mo ago
    MobileAuto-check passed
  • Ha Android Architecture

    home-assistant/android

    Home Assistant Android module and layer architecture. An agent skill from home-assistant/android.

    4k GitHub stars~1.7k tokensUpdated yesterday
    MobileAuto-check passed
  • Architecture Overclock

    nekomangaorg/Neko

    Resolves deep, structural performance bottlenecks in the Kotlin Android codebase.

    2.8k GitHub stars~1.4k tokensUpdated yesterday
    MobileAuto-check passed
  • Claude Android Ninja

    Drjacky/claude-android-ninja

    Build and migrate Android apps with Kotlin, Jetpack Compose, MVVM, Hilt, Room 3 (KSP, SQLiteDriver, Flow/suspend DAOs), Navigation3, and multi-module Gradle.

    124 GitHub stars~5.2k tokensUpdated 9 days ago
    MobileAuto-check passed

More from timusus/Shuttle2

All 13 skills in this repo
  • Debug Receivers

    timusus/Shuttle2

    Drive the S2 debug build's playback and queue over ADB broadcasts — play the whole library, play/pause, skip, seek, remove a queue item, toggle shuffle/repeat, dump playback state as JSON, reimport…

    229 GitHub stars~1.9k tokensUpdated yesterday
    Auto-check passed
  • Deploy Android

    timusus/Shuttle2

    Deploy the Android app to the Play Store via GitHub Actions.

    229 GitHub stars~1.2k tokensUpdated yesterday
    Auto-check passed
  • Reply Reviews

    timusus/Shuttle2

    Weekly Play Store review flow for S2: fetch new reviews, draft replies, get owner approval, then post.

    229 GitHub stars~1k tokensUpdated yesterday
    Auto-check passed
  • Check

    timusus/Shuttle2

    Run lint + unit tests, investigate and fix failures. An agent skill from timusus/Shuttle2.

    229 GitHub stars~449 tokensUpdated yesterday
    Auto-check passed
  • Commit

    timusus/Shuttle2

    Analyse working tree changes, group them into logical atomic commits, and create well-structured conventional commits with module scopes.

    229 GitHub stars~1.9k tokensUpdated yesterday
    Auto-check: notes
  • Delegate Verbose

    timusus/Shuttle2

    Run high-volume work in a subagent so its raw output never enters this conversation.

    229 GitHub stars~864 tokensUpdated yesterday
    Auto-check passed

Works with

Categories

Questions about Android Coroutine Testing

What does Android Coroutine Testing do?

Comprehensive guidance for writing deterministic tests for Android code using Kotlin coroutines. Android Coroutine Testing is an agent skill from timusus/Shuttle2. Comprehensive guidance for writing deterministic tests for Android code using Kotlin coroutines.

When should I use Android Coroutine Testing?

Android Coroutine Testing fits situations like: testing suspending functions; viewModels with coroutines; needing to handle test dispatchers; backgroundScope.

How do I install Android Coroutine Testing in Claude Code?

Run `npx skills add timusus/Shuttle2 --skill android-coroutine-testing -a claude-code`. Or copy the skill folder (.claude/skills/android-coroutine-testing in timusus/Shuttle2) into .claude/skills/android-coroutine-testing in your project. Claude Code loads it when a task matches its description.

How do I install Android Coroutine Testing in Codex?

Run `npx skills add timusus/Shuttle2 --skill android-coroutine-testing -a codex`. Or copy the skill folder (.claude/skills/android-coroutine-testing in timusus/Shuttle2) into .agents/skills/android-coroutine-testing in your project. Codex loads it when a task matches its description.

Can I use Android Coroutine Testing in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add timusus/Shuttle2 --skill android-coroutine-testing -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/android-coroutine-testing, .gemini/skills/android-coroutine-testing, .github/skills/android-coroutine-testing and .opencode/skills/android-coroutine-testing in your project.

What does Android Coroutine Testing need to run?

SKILL.md names no scripts, command-line tools or credentials: Android Coroutine Testing is instructions for the agent only.

Does Android Coroutine Testing access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Android Coroutine Testing safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Android Coroutine Testing use?

Android Coroutine Testing is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Android Coroutine Testing use?

About 1.2k tokens (SKILL.md is roughly 4.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Android Coroutine Testing?

Skills that share tags, products or a category with Android Coroutine Testing: Android Hidden API and R8 Check (gkd-kit/gkd, 43k stars), Compose Multiplatform Patterns (monta-app/ocpp-emulator, 180 stars), Android Development (dpconde/claude-android-skill, 336 stars) and Ha Android Architecture (home-assistant/android, 4k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Android Coroutine Testing?

timusus (a GitHub user) maintains it in timusus/Shuttle2, which has 229 GitHub stars. The repository holds 13 skills in this directory. The repository was last updated on October 7, 2026.

Source: timusus/Shuttle2 on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.