Cash App's Flow testing with Turbine
Original post Flow testing with Turbine
Article Summary
Cash App just open-sourced Turbine 1.0, solving one of the trickiest parts of Kotlin coroutines: testing Flows without the headache.
Jake Wharton and the Cash App team released Turbine, a library that transforms push-based Flow operations into pull-based suspend functions. It's designed to make async Flow testing feel as simple as writing synchronous test assertions.
Key Takeaways
- Converts push-based Flows into pull-based suspend functions for intuitive testing
- awaitItem() and awaitComplete() pause until events occur, throwing AssertionError on mismatch
- Standalone Turbines adapt callbacks and other push mechanisms beyond Flows
- Advanced utilities handle multiple Flows, shared timeouts, and aggregated errors
Turbine eliminates the complexity of async Flow testing by letting you write sequential, readable test assertions with automatic timeout and error handling.
Continue reading
What This Article Covers
Testing kotlinx.coroutines Flow is tricky because it's push-based and asynchronous. Writing assertions in sequence normally requires complex synchronization logic.
Cash App's Turbine library changes how Flow works in tests. It converts push-based operations into pull-based suspend functions, so developers can call awaitItem() and awaitComplete() in regular test blocks.
Flow tests become much simpler to write. Developers get sequential assertions and automatic timeout handling without manual synchronization or complicated async patterns.
This page summarizes “Flow testing with Turbine” by Cash App, published Jun 21, 2023. All credit for the original work goes to the authors.