is there a way to override Dispatchers.UI on unit ...
# coroutines
a
is there a way to override Dispatchers.UI on unit tests in android? it's trying to use Looper.getMainLooper() which is a stubbed method
g
Do not use Dispatcher.UI directly, instead pass it as dependency of your coroutine scope
a
I'm not using it, it's because of this line:
internal val mainHandler = Looper.getMainLooper().asHandler(async = true)
in the
HandlerDispatcher.kt
in coroutines-android
which is a top level variable
z
Your test subject shouldn't hard-code
Dispatchers.UI
. You should inject a dispatcher so you can pass a different one in from your unit tests.