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
Critical Insight
Turbine eliminates the complexity of async Flow testing by letting you write sequential, readable test assertions with automatic timeout and error handling.