Cash App Jake Wharton

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

Critical Insight

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

Problem

Testing kotlinx.coroutines Flow is tricky because it's push-based and asynchronous. Writing assertions in sequence normally requires complex synchronization logic.

Solution

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.

Impact

Flow tests become much simpler to write. Developers get sequential assertions and automatic timeout handling without manual synchronization or complicated async patterns.

The standalone Turbine pattern opens up creative testing possibilities beyond just Flow that most developers haven't considered yet.

This page summarizes “Flow testing with Turbine” by Cash App, published Jun 21, 2023. All credit for the original work goes to the authors.

Read the original on code.cash.app (opens in new tab)

AI tools for iOS

Browse all AI tools →