Jeziel Lago
04/13/2021, 2:46 PMMutableSharedFlow
?
@Test
fun testIntSharedFlow() = runBlockingTest {
val intSharedFlow = MutableSharedFlow<Int>()
intSharedFlow.emit(5)
assertEquals(5, intSharedFlow.single())
}
This code results java.lang.IllegalStateException: This job has not completed yet
ephemient
04/13/2021, 4:25 PM.single()
can't work on a SharedFlow, since it never terminatesephemient
04/13/2021, 4:27 PMval intSharedFlow = MutableSharedFlow<Int>(replay = 1)
intSharedFlow.emit(5)
assertEquals(5, intSharedFlow.first())
I'd expect that to workJavier
04/13/2021, 4:36 PMJeziel Lago
04/13/2021, 5:02 PMfirst()
not works.ephemient
04/13/2021, 5:03 PMreplay = 1
as well? the default replay = 0
doesn't work with thisJeziel Lago
04/13/2021, 5:07 PMreplay = 1
it works, but I need replay = 0
.Javier
04/13/2021, 5:10 PMJeziel Lago
04/13/2021, 5:12 PMtoList().first()
not works too.
Turbine library seems a good option. Thanks @Javier
I’m disappointed with the Kotlin test library does not work with this use case.Javier
04/13/2021, 5:13 PMephemient
04/13/2021, 6:09 PMreplay = 0
- need to subscribe to the flow before emittingephemient
04/13/2021, 6:11 PMval intSharedFlow = MutableSharedFlow<Int>()
intSharedFlow.test {
intSharedFlow.emit(5)
assertEquals(5, expectItem())
}
Jeziel Lago
04/13/2021, 6:36 PMJeziel Lago
04/13/2021, 6:46 PMelizarov
04/13/2021, 9:08 PMJeziel Lago
04/13/2021, 9:50 PMprovides testing utilities for effectively testing coroutines
, that not help us so much (testing MutableSharedFlow as an example).
IMHO, is very important to provide utilities (or ways and to show how) to test new components when releasing them to the community.
Thanks all for helping me!