https://kotlinlang.org logo
Title
s

Saiedmomen

01/12/2019, 12:21 AM
I'm getting this error while running junit test in android module
Exception in thread "main" java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used
Does anyone know
Dispatchers.setMain
with what parameter should be called?
a

Allan Wang

01/12/2019, 12:22 AM
Did you import an appropriate dependency to set your main dispatcher?
See https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md Otherwise you need the test dependency to set your own main dispatcher
s

Saiedmomen

01/12/2019, 12:25 AM
the one mentioned in the message of exception? yes#
I just don't know what to pass into setMain
a

Allan Wang

01/12/2019, 12:27 AM
Are you not using android, swing, or javafx? Do you actually need a main dispatcher?
s

Saiedmomen

01/12/2019, 12:28 AM
yes. android. It is working on main source set. It is throwing this in junit test
Thank you but I'm still getting the same exception
a

Allan Wang

01/12/2019, 12:37 AM
Can you post your unit test?
s

Saiedmomen

01/12/2019, 12:46 AM
it is in the channel