Johnjake Talledo
09/09/2021, 8:50 AMunit test I was testing hot flow / MutableSharedFlow inside my runBlockTest I need to collect the flows then cancel the job, launch return Job and coroutineScope return a Unit and both of them can call suspending function If I use both launch it will work I get the desired output which is 10, but if I used coroutineScope to collect the flows and cancel the using launch I get Job was cancelled or instead of launch using both coroutineScope I get the same error. Why? Also if I use move the delay to first launch collection, I get the same prompt error of Job was cancelled, I thought I was running parallel execution e.g: like launch1 after completed launch2 then cancel the entire TestCoroutineScope.Johnjake Talledo
09/09/2021, 8:53 AM@ExperimentalCoroutinesApi
class MainCoroutineRule(
val job: Job = Job(),
private val dispatcher: CoroutineDispatcher = TestCoroutineDispatcher()
) : TestWatcher(), TestCoroutineScope by TestCoroutineScope(job + dispatcher) {
override fun starting(description: Description?) {
super.starting(description)
Dispatchers.setMain(dispatcher)
}
override fun finished(description: Description?) {
super.finished(description)
cleanupTestCoroutines()
Dispatchers.resetMain()
}
}Mateusz Apacki
09/09/2021, 3:03 PM