https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

Marko Novaković

10/02/2023, 11:59 AM
in my
ViewModel
I’m not using
viewModelScope
but I’m passing
coroutineScope
as a constructor argument. in tests I’m passing
UnconfinedTestDispatcher()
as
coroutimeScope
but my tests don’t work unless I do
Dispatchers.setMain(UnconfinedTestDispatcher())
even tho I’m not using
viewModelScope
. why is that?
s

Sam

10/02/2023, 12:07 PM
If you're using
runTest
then calling
setMain
will also affect which dispatcher the code in the test itself is running on. Could that account for the difference?
m

Marko Novaković

10/02/2023, 12:08 PM
indeed, I’m using
runTest