I read that Kotest has built-in coroutine test sup...
# kotest
l
I read that Kotest has built-in coroutine test support. How can I get access to the
Dispatcher
instance used inside a
Spec
? I'm testing Android ViewModel and for this need to replace the
Main
dispatcher inside
viewModelScope
using
Dispatchers.setMain()
.
s
Getting the current dispatcher should be as simple as
val dispatcher = coroutineContext[CoroutineDispatcher]
, just as in normal code. If you have set
coroutineTestScope = true
for your test suite, the dispatcher will be a
TestDispatcher
— see https://kotest.io/docs/framework/coroutines/test-coroutine-dispatcher.html
🌟 1
l
Thank you so much for your quick and helpful answer! That is indeed very easy 🙏
192 Views