testing-flows-with-turbine

Installation
SKILL.md

Testing Flows With Turbine — Assert Emissions Without toList Hangs

Turbine is the canonical way to assert Flow emissions one-at-a-time, with built-in cancellation that prevents hot flows (StateFlow, SharedFlow) from hanging the test. This skill covers flow.test, the ReceiveTurbine API, turbineScope for multi-flow tests, and when raw flow.toList() actually beats Turbine. The non-Flow coroutine plumbing is ../testing-coroutines-with-runtest/SKILL.md.

When to use this skill

  • The class under test exposes a StateFlow<UiState> or SharedFlow<Event> and the test must assert each emission.
  • A test hangs on flow.toList() over a SharedFlow or StateFlow — neither completes.
  • The developer wants to assert "no more emissions for a beat" or "the next event is an error", which toList() cannot express.
  • Two flows must be observed concurrently (e.g. uiState plus a one-shot events flow) and asserted in interleaved order.
  • The build error is TurbineAssertionError: Unconsumed events found or Expected an item but found Complete/Error.
  • The developer mentions Turbine APIs: awaitItem, awaitComplete, awaitError, expectMostRecentItem, skipItems, expectNoEvents, withTurbineTimeout, turbineScope, testIn.

When NOT to use this skill

  • The test is about runTest, TestScope, Dispatchers.setMain, or virtual time. Use ../testing-coroutines-with-runtest/SKILL.md first; Turbine sits on top of runTest.
  • The flow is cold and completes deterministically, and the assertion is "the full list equals X". flow.toList() is shorter — see Decision matrix below.
  • The "flow" is actually Compose snapshot state. Read it via the test rule, not Turbine.
Installs
38
GitHub Stars
319
First Seen
May 16, 2026
testing-flows-with-turbine — skydoves/android-testing-skills