Logo Testing Flows With Turbine

Testing Flows With Turbine

Cộng đồng
skydoves
testing-flows-with-turbine

Dùng kỹ năng này để xác nhận các giá trị Flow phát ra trong bài kiểm thử bằng Cash App Turbine. Nội dung bao gồm cách bắt đầu bằng flow.test, API ReceiveTurbine (awaitItem, awaitComplete, awaitError, expectMostRecentItem, skipItems, expectNoEvents, cancel và các hàm liên quan, cùng với takeItem/takeComplete/takeError không cần suspend), turbineScope/testIn để kiểm thử nhiều flow, kênh Turbine<T> độc lập (add/close/asChannel/ensureAllEventsConsumed) để xác minh callback và listener không phải Flow, quy tắc hủy của luồng nóng so với luồng lạnh (StateFlow/SharedFlow không bao giờ tự hoàn tất), thời gian chờ theo đồng hồ thực của Turbine không phụ thuộc vào thời gian ảo của runTest và bảng quyết định chọn Turbine hay flow.toList thuần. Nếu người dùng nhắc đến Turbine, awaitItem, awaitComplete, expectMostRecentItem, takeItem, “bài kiểm thử bị treo khi collect”, “SharedFlow không bao giờ hoàn tất”, “lần phát đầu tiên của StateFlow”, “TurbineAssertionError”, “withTurbineTimeout”, kênh “Turbine()”, “ghi lại callback trong bài kiểm thử” hoặc xác nhận StateFlow/SharedFlow của ViewModel, hãy dùng kỹ năng này.

Add to TypingMind

Tổng quan

Nhà phát hànhskydoves
Kho mãandroid-testing-skills
Tên kỹ năngtesting-flows-with-turbine
Sao
338
Bản fork
14
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépApache-2.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được skydoves công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Testing Flows With Turbine trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/skydoves/android-testing-skills/tree/main/jvm-tests/coroutines/testing-flows-with-turbine
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/skydoves/android-testing-skills.git /tmp/android-testing-skills
mkdir -p .claude/skills
cp -r /tmp/android-testing-skills/jvm-tests/coroutines/testing-flows-with-turbine .claude/skills/testing-flows-with-turbine
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Testing Flows With Turbine trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Testing Flows With Turbine ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Testing Flows With Turbine với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

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.

Prerequisites

  • Gradle: testImplementation("app.cash.turbine:turbine:1.x") (docs/CORPUS.md §G.1; R5).
  • Turbine multiplatform — JVM, Android, iOS, JS, Native, wasm. Apache 2.0, Square / Cash App.
  • The surrounding test must be a runTest { … } body (or any suspend context). flow.test { } is itself suspend.
  • For multi-flow tests, @OptIn(ExperimentalCoroutinesApi::class) because turbineScope interacts with TestScope.backgroundScope.

flow.test signature

kotlin
public suspend fun <T> Flow<T>.test(
    timeout: Duration = 3.seconds,
    name: String? = null,
    validate: suspend ReceiveTurbine<T>.() -> Unit,
)

(docs/CORPUS.md §G; R5.) Three things to internalize:

  1. test { } launches a new coroutine that calls flow.collect { } and feeds every emission into a ReceiveTurbine<T> channel. The collector is attached before validate { } runs, so it is safe to emit into a hot flow from inside the block without dropping the first item.
  2. The 3-second default timeout is wall clock — it is NOT driven by TestCoroutineScheduler and does NOT honor runTest's virtual time. awaitItem() waits up to 3 real seconds.
  3. After validate { } returns, Turbine asserts no unconsumed events remain. If any item / completion / error is pending, it throws TurbineAssertionError. The collecting coroutine is then cancelled, so cold flows do not leak.

The name argument is appended to error messages — invaluable when multiple turbines run in one test.

ReceiveTurbine API

kotlin
public interface ReceiveTurbine<T> {
    // suspending
    public suspend fun awaitItem(): T
    public suspend fun awaitComplete()
    public suspend fun awaitError(): Throwable
    public suspend fun awaitEvent(): Event<T>
    public suspend fun skipItems(count: Int)
    public suspend fun cancel()
    public suspend fun cancelAndIgnoreRemainingEvents()
    public suspend fun cancelAndConsumeRemainingEvents(): List<Event<T>>

    // non-suspending
    public fun expectNoEvents()
    public fun expectMostRecentItem(): T
    public fun ensureAllEventsConsumed()
}

(R5.)

CallUse when
awaitItem(): TNext event must be an item; fails on Complete/Error.
awaitComplete()Next event must be flow completion; fails on item/error.
awaitError(): ThrowableNext event must be an error; returns the throwable for further assertions.
awaitEvent(): Event<T>Sealed-class entry: Event.Item(value), Event.Complete, Event.Error(throwable).
skipItems(n)Drop n item events; fails if anything but an item is next. Useful to skip a StateFlow's seed.
expectMostRecentItem()Non-suspending; drains buffered items and returns the latest. The "final state" assertion for StateFlow-driven UIs where intermediate values are lossy.
expectNoEvents()Non-suspending; throws if anything is buffered. Pair with runCurrent()/advanceTimeBy(...) to assert no spurious emissions.
cancel()Stop the collector; any remaining events become an assertion failure on scope exit.
cancelAndIgnoreRemainingEvents()Stop, drain silently. The default tail of any hot-flow test.
cancelAndConsumeRemainingEvents()Returns List<Event<T>> for ad-hoc inspection.

Hot vs cold flow contract

Flow typeCompletes naturally?First awaitItem() returnsNeed cancel()?
flowOf(...) / flow { } (cold)yesfirst emissionno — awaitComplete() terminates
MutableSharedFlow<T> (replay = 0)nonext emission (or hangs)always
MutableStateFlow<T>noseed value (replay = 1)always

(docs/CORPUS.md §G; R5.)

CRITICAL: SharedFlow and StateFlow never call onCompletion. awaitComplete() on either will hang to the 3-second wall-clock timeout. Always end with cancel() (or cancelAndIgnoreRemainingEvents()).

StateFlow.test always emits the seed value first because StateFlow has replay = 1. If you do not care about the seed, skipItems(1) it.

turbineScope and testIn — multiple flows in one test

kotlin
public suspend fun <R> turbineScope(
    timeout: Duration? = null,
    validate: suspend TurbineTestContext.() -> R,
): R

public fun <T> Flow<T>.testIn(
    scope: CoroutineScope,
    timeout: Duration? = null,
    name: String? = null,
): ReceiveTurbine<T>

Use these when assertions are interleaved between two flows:

kotlin
runTest(mainRule.dispatcher) {
    turbineScope {
        val items = repo.items.testIn(backgroundScope, name = "items")
        val errors = repo.errors.testIn(backgroundScope, name = "errors")
        assertEquals(0, items.awaitItem())
        assertEquals(emptyList<Throwable>(), errors.expectMostRecentItem())
        items.cancel()
        errors.cancel()
    }
}

testIn requires explicit cancel() (or awaitComplete() / awaitError()) before the turbineScope ends; otherwise the scope assertion throws.

Standalone Turbine<T> — capturing callbacks and one-shot signals

Turbine is not only a Flow adapter. The standalone Turbine<T> is a send-and-receive channel with the same ReceiveTurbine assertion surface — for when the thing under test is not a Flow: a (T) -> Unit callback, a listener interface, a Channel you own, a hand-rolled fake that needs to record invocations.

kotlin
public fun <T> Turbine(timeout: Duration? = null, name: String? = null): Turbine<T>

public interface Turbine<T> : ReceiveTurbine<T> {
    public val isClosed: Boolean
    public fun add(item: T)                       // producer side — push an item
    public fun close(cause: Throwable? = null)    // signal Complete (or Error if cause != null)
    public fun asChannel(): Channel<T>            // hand the producer a plain SendChannel
}

(docs/CORPUS.md §G; R5.) It turns "was this callback invoked with X, and only that?" into the same awaitItem() vocabulary:

kotlin
@Test fun emitsClickedId() = runTest(mainRule.dispatcher) {
    val clicks = Turbine<Long>()
    val adapter = ItemAdapter(onClick = clicks::add)        // production code calls onClick(id)

    adapter.bind(item)
    adapter.simulateClick()

    assertEquals(42L, clicks.awaitItem())
    clicks.ensureAllEventsConsumed()                        // no extra invocations slipped through
}

ensureAllEventsConsumed() asserts nothing is left buffered — the standalone-Turbine equivalent of the check flow.test { } runs implicitly on block exit. A standalone Turbine never auto-completes, so awaitComplete() on one hangs to the timeout unless you close() it; treat it like a hot flow.

Synchronous (non-suspend) consumption: takeItem / takeComplete / takeError

When the assertion site cannot suspend — a plain @Test body after the producing coroutine already ran, an assert inside a non-suspend callback — ReceiveTurbine exposes non-suspending takers that require the event to be buffered already and throw if it is not:

kotlin
public fun takeItem(): T
public fun takeComplete()
public fun takeError(): Throwable
kotlin
@Test fun synchronousDrain() = runTest(mainRule.dispatcher) {
    val turbine = vm.uiState.testIn(backgroundScope)
    advanceUntilIdle()                              // let the producer run to quiescence (virtual time)
    assertEquals(Idle, turbine.takeItem())          // no suspension — the value is already buffered
    assertEquals(Loaded, turbine.takeItem())
    turbine.cancel()
}

Prefer suspending awaitItem() inside runTest / flow.test blocks; reach for takeItem() only when the call site genuinely cannot suspend.

Turbine timeout vs runTest virtual time

Turbine's 3-second default is wall clock, never virtual. runTest's 60-second default is also wall clock — but advanceTimeBy(...) inside the test body manipulates TestCoroutineScheduler virtual time, which Turbine does not see.

Implication: a test using delay(10.minutes) finishes in microseconds because runTest skips the delay. But a flow.test { awaitItem() } that waits for an emission whose source is real network I/O still observes real wall-clock time. If the wait is genuinely longer than 3 seconds in real time, override:

kotlin
flow.test(timeout = 10.seconds) { … }            // per-call

withTurbineTimeout(10.seconds) {                 // scoped
    flow.test { … }
}

Decision matrix — Turbine vs raw flow.toList()

ScenarioPick
Cold flow that completes; "the full list equals X"flow.toList() (shorter)
Hot StateFlow / SharedFlowTurbine (handles cancellation)
Need to assert intermediate state then trigger more emissionsTurbine
Need to assert "no more events for a while"Turbine (expectNoEvents)
Need to assert error type / completionTurbine (awaitError, awaitComplete)
Multiple flows interleaved in one testTurbine (turbineScope/testIn)
Multiplatform test on JS/NativeBoth work; Turbine is easier
Zero extra dependencyflow.toList()

(R5.)

Rule of thumb: prefer Turbine for any UI-state / ViewModel test (almost always StateFlow-driven), and flow.toList() for repository/transformation tests of cold flows that complete deterministically.

Patterns

Pattern: WRONG — flow.toList() on a SharedFlow

kotlin
// WRONG
@Test fun events() = runTest {
    val events: SharedFlow<Event> = vm.events
    val collected = events.toList()                 // never returns
    assertEquals(listOf(LoggedIn), collected)
}
// WRONG because: SharedFlow never completes. toList() suspends until the upstream
// completes, which it never does. The test hangs to the 60s runTest timeout.
kotlin
// RIGHT
@Test fun events() = runTest(mainRule.dispatcher) {
    vm.events.test {
        vm.login()
        assertEquals(LoggedIn, awaitItem())
        cancelAndIgnoreRemainingEvents()             // hot flow — must cancel
    }
}

Pattern: WRONG — forgetting StateFlow's seed value

kotlin
// WRONG
@Test fun stateFlowEmits() = runTest(mainRule.dispatcher) {
    vm.uiState.test {
        vm.refresh()
        assertEquals(Loading, awaitItem())           // FAIL: actually Idle (seed)
        cancel()
    }
}
// WRONG because: StateFlow has replay = 1. The collector immediately receives the
// current value (Idle) before any new emission. The first awaitItem() returns
// the seed, not the post-refresh state.
kotlin
// RIGHT — assert the seed
@Test fun stateFlowEmits() = runTest(mainRule.dispatcher) {
    vm.uiState.test {
        assertEquals(Idle, awaitItem())              // seed
        vm.refresh()
        assertEquals(Loading, awaitItem())
        assertEquals(Success(items), awaitItem())
        cancelAndIgnoreRemainingEvents()
    }
}

// RIGHT — skip the seed if you do not care
@Test fun stateFlowEmits_skipSeed() = runTest(mainRule.dispatcher) {
    vm.uiState.test {
        skipItems(1)
        vm.refresh()
        assertEquals(Loading, awaitItem())
        assertEquals(Success(items), awaitItem())
        cancelAndIgnoreRemainingEvents()
    }
}

Pattern: WRONG — awaitComplete() on a hot flow

kotlin
// WRONG
@Test fun events() = runTest {
    vm.events.test {
        vm.login()
        assertEquals(LoggedIn, awaitItem())
        awaitComplete()                              // hangs 3s, then TurbineAssertionError
    }
}
// WRONG because: SharedFlow never completes. awaitComplete() waits 3 wall-clock
// seconds (Turbine default) and then throws. The test is slow AND fails.
kotlin
// RIGHT
@Test fun events() = runTest(mainRule.dispatcher) {
    vm.events.test {
        vm.login()
        assertEquals(LoggedIn, awaitItem())
        cancelAndIgnoreRemainingEvents()
    }
}

Pattern: conflated StateFlow — use expectMostRecentItem

kotlin
@Test fun finalState() = runTest(mainRule.dispatcher) {
    vm.uiState.test {
        skipItems(1)                                 // seed
        vm.flipFast()                                // posts 5 transitions in <1ms
        advanceUntilIdle()                           // virtual; let coroutines settle
        // StateFlow conflates — only the latest value is kept.
        // awaitItem() may see anything from the burst; expectMostRecentItem is deterministic.
        assertEquals(Final, expectMostRecentItem())
        cancelAndIgnoreRemainingEvents()
    }
}

Pattern: assert "no more events"

kotlin
@Test fun noSpuriousEmissions() = runTest(mainRule.dispatcher) {
    vm.uiState.test {
        skipItems(1)
        vm.refresh()
        assertEquals(Loading, awaitItem())
        assertEquals(Success(items), awaitItem())
        advanceTimeBy(5.seconds)                     // virtual — flush any timers
        runCurrent()
        expectNoEvents()                             // confirms quiescence
        cancelAndIgnoreRemainingEvents()
    }
}

Pattern: cold flow that completes — Turbine vs toList

kotlin
// FINE — toList() is shorter for terminal cold flows
@Test fun coldList() = runTest {
    val collected = flowOf(1, 2, 3).toList()
    assertEquals(listOf(1, 2, 3), collected)
}

// ALSO FINE — Turbine if you need intermediate-state assertions
@Test fun coldTurbine() = runTest {
    flowOf(1, 2, 3).test {
        assertEquals(1, awaitItem())
        assertEquals(2, awaitItem())
        assertEquals(3, awaitItem())
        awaitComplete()                              // cold flow — completes naturally
    }
}

Pattern: two flows interleaved with turbineScope

kotlin
@Test fun interleaved() = runTest(mainRule.dispatcher) {
    turbineScope {
        val state = vm.uiState.testIn(backgroundScope, name = "state")
        val events = vm.events.testIn(backgroundScope, name = "events")
        assertEquals(Idle, state.awaitItem())
        vm.login()
        assertEquals(Loading, state.awaitItem())
        assertEquals(LoggedIn, events.awaitItem())
        assertEquals(Success, state.awaitItem())
        state.cancel(); events.cancel()
    }
}

Mandatory rules

  • MUST wrap any StateFlow / SharedFlow assertion in flow.test { … cancelAndIgnoreRemainingEvents() }. MUST NOT call flow.toList() on a hot flow — the test hangs.
  • MUST call cancel() / cancelAndIgnoreRemainingEvents() at the end of every test { } block over a hot flow. awaitComplete() is wrong for hot flows — they never complete.
  • MUST account for StateFlow's seed value: the first awaitItem() returns the current value (replay = 1). Either assert it or skipItems(1).
  • MUST depend on Turbine from testImplementation only. MUST NOT put app.cash.turbine on implementation.
  • MUST override withTurbineTimeout(...) (or per-call timeout =) when the awaited emission genuinely takes more than 3 wall-clock seconds. The 3 s default is wall clock and is independent from runTest virtual time.
  • MUST use cancel() (NOT awaitComplete()) inside testIn blocks before turbineScope ends; otherwise the scope assertion throws.
  • MUST NOT mix Turbine timeouts with runTest's virtual clock semantics. advanceTimeBy(10.minutes) is virtual; Turbine's 3-second wait is real.
  • PREFERRED: expectMostRecentItem() for deterministic "final state" assertions on conflated StateFlow where intermediate values may be collapsed.
  • PREFERRED: raw flow.toList() for cold flows that complete deterministically — Turbine is overhead in that case.
  • PREFERRED: name turbines (flow.test(name = "uiState"), flow.testIn(scope, name = "events")) when more than one runs in a test — error messages cite the name.
  • PREFERRED: the standalone Turbine<T>() (with add / close / ensureAllEventsConsumed) over a manually accumulated MutableList when verifying a (T) -> Unit callback or a listener was invoked — it gives the same awaitItem() diagnostics and the unconsumed-event check.
  • PREFERRED: suspending awaitItem() inside runTest / flow.test blocks over the non-suspending takeItem() / takeComplete() / takeError(); reach for the takers only when the call site genuinely cannot suspend.

Verification

  • No flow.toList() call exists on any StateFlow or SharedFlow (grep -rn 'toList()' src/test cross-checked against flow types).
  • Every flow.test { … } over a hot flow ends with cancel() or cancelAndIgnoreRemainingEvents().
  • No awaitComplete() is called on a StateFlow / SharedFlow.
  • StateFlow tests either assert the seed via awaitItem() or skipItems(1) before further assertions.
  • Turbines that may legitimately wait > 3 s use withTurbineTimeout(...) or per-call timeout = N.seconds.
  • Multi-flow tests use turbineScope { … testIn(backgroundScope) … } rather than nested test { } blocks.
  • Callback / listener assertions use a standalone Turbine<T>() (with ensureAllEventsConsumed()), not an ad-hoc MutableList.
  • CI run completes 50 iterations without TurbineAssertionError flakes.

References

  • Cash App Turbine — README and API: https://github.com/cashapp/turbine
  • Cash App Turbine — releases: https://github.com/cashapp/turbine/releases
  • Android Developers — Test Kotlin Flow on Android: https://developer.android.com/kotlin/flow/test
  • Android Developers — StateFlow & SharedFlow: https://developer.android.com/kotlin/flow/stateflow-and-sharedflow
  • JetBrains — Asynchronous Flow: https://kotlinlang.org/docs/flow.html
  • Research: tasks/research/R5-coroutines-test-turbine.md — Turbine API surface, hot/cold contract, comparison with toList().
  • docs/CORPUS.md §G.1 — Gradle coordinates and version pin.
  • Sibling: ../testing-coroutines-with-runtest/SKILL.md — runTest, MainDispatcherRule, virtual time foundations Turbine sits on top of.
  • Sibling: ../../mocking/mocking-with-mockito/SKILL.md — mocking suspend dependencies that produce flows.
  • Sibling: ../../mocking/mocking-with-mockk/SKILL.md — coEvery { repo.items() } returns flowOf(...).
  • Sibling: ../../runner/configuring-junit4-on-android/SKILL.md — JUnit4 plumbing.
  • Sibling: ../../robolectric/using-robolectric-correctly/SKILL.md — when the SUT needs Android framework on the JVM.
  • Cross-set: ../../../fundamentals/strategies/applying-testing-strategies/SKILL.md — small/medium/big sizing for Flow tests.
  • Cross-set: ../../../fundamentals/strategies/organizing-test-source-sets/SKILL.md — where Flow tests belong (src/test/).
  • Cross-set: ../../../compose/synchronization/controlling-the-test-clock/SKILL.md — Compose's MainTestClock is independent of Turbine's wall clock.
  • Cross-set: ../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.md — Turbine works on-device too, with the same API.
  • Cross-set: ../../../kotlin/kotlin-test/writing-tests-with-kotlin-test/SKILL.md — awaitItem() paired with kotlin.test's assertEquals / assertIs; the assertion vocabulary inside flow.test { }.

Câu hỏi thường gặp

Kỹ năng AI Testing Flows With Turbine làm được gì?

Dùng kỹ năng này để xác nhận các giá trị Flow phát ra trong bài kiểm thử bằng Cash App Turbine. Nội dung bao gồm cách bắt đầu bằng flow.test, API ReceiveTurbine (awaitItem, awaitComplete, awaitError, expectMostRecentItem, skipItems, expectNoEvents, cancel và các hàm liên quan, cùng với takeItem/takeComplete/takeError không cần suspend), turbineScope/testIn để kiểm thử nhiều flow, kênh Turbine<T> độc lập (add/close/asChannel/ensureAllEventsConsumed) để xác minh callback và listener không phải Flow, quy tắc hủy của luồng nóng so với luồng lạnh (StateFlow/SharedFlow không bao giờ tự hoàn tất),...

Vì sao nên dùng Testing Flows With Turbine trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Testing Flows With Turbine là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Testing Flows With Turbine trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/skydoves/android-testing-skills/tree/main/jvm-tests/coroutines/testing-flows-with-turbine. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Testing Flows With Turbine?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Testing Flows With Turbine với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Testing Flows With Turbine với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Testing Flows With Turbine có miễn phí không?

Có. Kỹ năng này được skydoves phát hành trên GitHub theo giấy phép Apache-2.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇