turbine
БесплатноБез исполняемых скриптовНе проверенTurbine — small Kotlin testing library for kotlinx.coroutines Flows. Provides ergonomic API to test Flow emissions deterministically: awaitItem…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Turbine — Flow Testing
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:turbine.
Why Turbine
Testing Flow is awkward without a helper:
Flow.toList()works for finite flows but never returns for hot/infinite ones- Manual
collect { }in test launches coroutines that race with assertions - StateFlow/SharedFlow have replay semantics that confuse test setup
Turbine gives a deterministic, suspend-friendly API:
flow.test {
awaitItem() shouldBe expected1
awaitItem() shouldBe expected2
cancelAndIgnoreRemainingEvents()
}
Used by Cash App, Square, JetBrains tooling teams. KMP-compatible.
Setup
// build.gradle.kts (or KMP commonTest)
testImplementation("app.cash.turbine:turbine:1.2.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.0")
// KMP
sourceSets.commonTest.dependencies {
implementation("app.cash.turbine:turbine:1.2.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.0")
}
Basic Usage
import app.cash.turbine.test
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
class FlowTest {
@Test fun `emits 3 items`() = runTest {
flowOf(1, 2, 3).test {
assertEquals(1, awaitItem())
assertEquals(2, awaitItem())
assertEquals(3, awaitItem())
awaitComplete()
}
}
}
test { } collects the flow within an isolated coroutine and exposes a DSL with assertion helpers.
API Reference
| Method | Purpose |
|---|---|
awaitItem(): T |
Wait for next emission, return it |
awaitItem(timeout: Duration) |
With custom timeout |
awaitComplete() |
Assert flow completes (no error) |
awaitError(): Throwable |
Wait for terminal error and return it |
expectNoEvents() |
Assert no pending emissions / completion / error |
expectMostRecentItem() |
Drain all pending emissions, return latest |
cancel() |
Cancel collection and verify no untested events |
cancelAndIgnoreRemainingEvents() |
Cancel and discard remaining emissions |
cancelAndConsumeRemainingEvents(): List<Event<T>> |
Cancel and return remaining as list |
skipItems(count: Int) |
Discard N items |
StateFlow Patterns
StateFlow always replays its current value to new collectors → first awaitItem() is the initial value.
@Test fun `state updates correctly`() = runTest {
val state = MutableStateFlow(0)
state.test {
assertEquals(0, awaitItem()) // initial
state.value = 1
assertEquals(1, awaitItem())
state.value = 2
assertEquals(2, awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
For ViewModel state flows:
@Test fun `loads wallets and updates state`() = runTest {
val viewModel = WalletViewModel(repo = fakeRepo)
viewModel.state.test {
// Initial state
val initial = awaitItem()
initial.isLoading shouldBe true
initial.wallets shouldBe emptyList()
// After load completes
val loaded = awaitItem()
loaded.isLoading shouldBe false
loaded.wallets shouldHaveSize 3
cancelAndIgnoreRemainingEvents()
}
}
SharedFlow / Events Pattern
@Test fun `emits navigation event on save`() = runTest {
val viewModel = WalletViewModel()
viewModel.events.test {
viewModel.save()
val event = awaitItem()
event.shouldBeInstanceOf<NavEvent.PopBack>()
cancelAndIgnoreRemainingEvents()
}
}
For replay-cache SharedFlow, you can use expectMostRecentItem():
@Test fun `most recent value`() = runTest {
val flow = MutableSharedFlow<Int>(replay = 1)
flow.emit(1)
flow.emit(2)
flow.emit(3)
flow.test {
// 3 was the last emission; replay buffer of 1 holds 3
assertEquals(3, expectMostRecentItem())
cancelAndIgnoreRemainingEvents()
}
}
Combine / Map / Filter
@Test fun `combine emits when either source changes`() = runTest {
val a = MutableStateFlow("foo")
val b = MutableStateFlow(1)
combine(a, b) { x, y -> "$x:$y" }.test {
assertEquals("foo:1", awaitItem())
a.value = "bar"
assertEquals("bar:1", awaitItem())
b.value = 2
assertEquals("bar:2", awaitItem())
cancelAndIgnoreRemainingEvents()
}
}
Debounce / FlatMapLatest (Virtual Time)
runTest provides virtual time. Use advanceTimeBy and advanceUntilIdle:
@Test fun `debounce filters fast input`() = runTest {
val source = MutableSharedFlow<String>()
source.debounce(300).test {
source.emit("a"); advanceTimeBy(100)
source.emit("ab"); advanceTimeBy(100)
source.emit("abc"); advanceTimeBy(400)
assertEquals("abc", awaitItem())
cancelAndIgnoreRemainingEvents()
}
Установить turbine в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditFAQ
Что делает скилл turbine?
Turbine — small Kotlin testing library for kotlinx.coroutines Flows. Provides ergonomic API to test Flow emissions deterministically: awaitItem, expectMostRecentItem, awaitComplete, awaitError. Works with StateFlow, SharedFlow, Channel-backed flows, combine/map/debounce. KMP-friendly. USE WHEN: user mentions "Turbine", "app.cash.turbine", ".test {}", "awaitItem", "Flow testing", "StateFlow test", "SharedFlow test", "expectMostRecentItem", "cancelAndIgnoreRemainingEvents" DO NOT USE FOR: Mobile E2E - use `testing/maestro` DO NOT USE FOR: Compose snapshot - use `testing/compose-snapshot` DO NOT USE FOR: Generic Kotlin testing - use `testing/kotest` DO NOT USE FOR: Suspend function (non-Flow) testing - use `kotlinx-coroutines-test` directly
Как установить скилл turbine?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл turbine запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic