Turbine (Kotlin Flow Testing)
Testing library for Kotlin's Flow, SharedFlow, and StateFlow. Turbine makes asserting on reactive streams ergonomic — instead of manually collecting flows in tests, call flow.test { awaitItem(), awaitComplete(), awaitError() } in a suspend test block. Handles coroutine timing, cancellation, and event ordering. Eliminates the boilerplate of collecting flows with launch {} and tracking items in a list.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Test library — no direct security surface. No network or credential handling. Cash App maintains.
⚡ Reliability
Best When
You're testing Kotlin Flow, StateFlow, or SharedFlow emissions and want readable, sequential assertions without manual coroutine boilerplate.
Avoid When
You need to test RxJava streams or non-Kotlin reactive frameworks — use framework-native test utilities instead.
Use Cases
- • Test Kotlin StateFlow and SharedFlow emissions from agent ViewModel logic without manual coroutine job management in tests
- • Assert the exact sequence of items emitted by agent data streams — awaitItem() blocks until the next emission for readable sequential assertions
- • Test flow completion and error scenarios in agent reactive pipelines — awaitComplete() and awaitError() make terminal event assertions concise
- • Use Turbine with multiple flows simultaneously (turbineScope) for testing agent state machines that coordinate multiple streams
- • Test agent repository flows that combine database updates with network responses in reactive patterns
Not For
- • Non-Kotlin reactive streams — Turbine targets Kotlin Flow only; use RxJava's TestObserver for RxJava testing
- • Flows that emit very high volumes of items — Turbine buffers items; high-frequency agent streams need custom collection strategies
- • Testing time-based flow operators in isolation — use kotlinx-coroutines-test TestCoroutineDispatcher for precise time control with delay-based flows
Interface
Authentication
Test library — no authentication.
Pricing
Cash App open source library. Apache 2.0 license.
Agent Metadata
Known Gotchas
- ⚠ Turbine requires kotlinx-coroutines-test for TestScope — using Turbine without TestCoroutineDispatcher causes timing issues in tests with delays
- ⚠ Unconsumed items cause test failure — if your flow emits 3 items but you only awaitItem() twice, Turbine fails with 'expected 0 unconsumed items'; use cancelAndConsumeRemainingEvents() to ignore
- ⚠ awaitItem() has a default timeout (1 second) — slow agent operations or flows waiting for data may timeout; configure timeout with .test(timeout = 5.seconds)
- ⚠ Turbine 1.x requires calling awaitComplete() or cancelAndIgnoreRemainingEvents() to end the test block cleanly — not calling either leaves the coroutine suspended
- ⚠ SharedFlow and StateFlow require special handling — SharedFlow with replay=0 may miss emissions before Turbine subscribes; use replay > 0 or synchronize emission timing
- ⚠ turbineScope { } for multiple flows runs flows concurrently — item ordering between different flows is non-deterministic and tests relying on cross-flow ordering are flaky
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for Turbine (Kotlin Flow Testing).
Scores are editorial opinions as of 2026-03-06.