testing-flows-with-turbine

Community

Assert Flow emissions safely without hangs

Authorskydoves
Version1.0.0
Installs0

System Documentation

What problem does it solve?

This Skill prevents Flow-based tests from hanging when asserting emissions from hot streams like StateFlow and SharedFlow by providing a one-at-a-time, cancellation-safe assertion workflow.

Core Features & Use Cases

  • Assert ordered emissions without toList(): Use flow.test { ... } / testIn(...) to await items, completion, or errors while ensuring no unconsumed events remain.
  • Correctly handle hot vs cold Flow behavior: Avoid waiting for completion on hot flows and instead use cancel() or cancelAndIgnoreRemainingEvents() to end the test deterministically.
  • Support multi-flow assertions: Use turbineScope and testIn to interleave assertions across multiple flows in the same test.
  • Also verify non-Flow callbacks: Use the standalone Turbine<T>() channel to capture listener/callback invocations with the same awaitItem()-style vocabulary.

Example use case

You have a ViewModel exposing uiState: StateFlow<UiState> and events: SharedFlow<Event> and you need to assert the initial seed value, the subsequent loading and success states, and a one-shot event in a single run without the test stalling.

Quick Start

Ask the AI to show how to write a runTest using vm.uiState.test { ... } that asserts the StateFlow seed, awaits the next two emissions, and finishes with cancelAndIgnoreRemainingEvents() to avoid hanging.

Dependency Matrix

Required Modules

None required

Components

Standard package

💻 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-flows-with-turbine
Download link: https://github.com/skydoves/android-testing-skills/archive/main.zip#testing-flows-with-turbine

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.