Using Dispatchers.setMain and Dispatchers.Main makes tests fail with:
Error: XXX: TestMainDispatcher is not set as main dispatcher, have Dispatchers.Main[missing] instead.
The simplest code to reproduce this problem:
https://pl.kotl.in/06K0zWkU2
class NewsViewModelTest {
@Test
fun test() {
val dispatcher = StandardTestDispatcher()
Dispatchers.setMain(dispatcher)
var a = 0
CoroutineScope(Dispatchers.Main + SupervisorJob()).launch {
delay(1000)
a = 1
}
dispatcher.scheduler.advanceUntilIdle()
assertEquals(1, a)
}
}
Seems that the coroutines and coroutines-test versions do not match.