Hi, for testing is there anyway to make my unit te...
# coroutines
j
Hi, for testing is there anyway to make my unit tests work if I use
Dispatchers.Main
dispatcher, or do I need to mock that guy? I'm getting
java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize
l
Hi @julioyg, you need to provide an implementation. I made an example in this PR: https://github.com/Kotlin/kotlinx.coroutines/pull/760/files Look for the
build.gradle
file,
TesMainDispatcher
, the
test/resources/META-INF/services/kotlinx.coroutines.internal.MainDispatcherFactory
file and the
LifecycleTest
file using it.
j
hey @louiscad I see the TestDispatcher, but I fail to see how to use it, and where to tell your tests to use it
l
It's automatically added via
ServiceLoader
with the resource in META-INF
@julioyg You then just have to use
Dispatchers.Main
j
ok... so I just copy that file under the same directory? sorry if it's a stupid question..
oh, it's working, thanks
l
It works because it's integrated into the resources sourceSets from
build.gradle
, or is in a default resources directory