test

suspend fun <T> Flow<T>.test(timeoutMs: Long = 1_000L, validate: suspend FlowTurbine<T>.() -> Unit)

Terminal flow operator that collects events from given flow and allows the validate lambda to consume and assert properties on them in order. If any exception occurs during validation the exception is rethrown from this method.

flowOf("one", "two").test {
assertEquals("one", expectItem())
assertEquals("two", expectItem())
expectComplete()
}

Parameters

timeoutMs

Duration in milliseconds each suspending function on FlowTurbine will wait before timing out.

suspend fun <T> Flow<T>.test(timeout: Duration, validate: suspend FlowTurbine<T>.() -> Unit)

Terminal flow operator that collects events from given flow and allows the validate lambda to consume and assert properties on them in order. If any exception occurs during validation the exception is rethrown from this method.

flowOf("one", "two").test {
assertEquals("one", expectItem())
assertEquals("two", expectItem())
expectComplete()
}

WARNING: This function uses experimental time support in Kotlin and requires that your Kotlin version and Kotlin coroutines version exactly match the version used by Turbine.

Parameters

timeout

Duration in milliseconds each suspending function on FlowTurbine will wait before timing out.