Anybody have a link to a sample of muultiplatform ...
# coroutines
t
Anybody have a link to a sample of muultiplatform common code to test methods that contain coroutines. I have seen dos about it, but I cannot get around the error of Dispatch.setMain message.
t
I only see a DateTest in the common text folder, and no coroutines tests. Not in the Android test area.
e
What kind of common test you are looking to write?
r
You can only easily test coroutines on the JVM right now...
t
Okay, tried again. I added what dependencies I think I am missing to my androidTest target. Then I get the following:
Copy code
IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used
So I add that to my @BeforeTest setUp method, then I get this:
Copy code
Dispatchers.setMain(Dispatchers.Main) is prohibited, probably Dispatchers.resetMain() should be used instead
This is why I asked for an existing working same of testing methods that internally use coroutines from commonTest. I can live with putting all API tests in android Test if needed, but I would like them to be tested when running iosTest too… Thank you.
An aside: I recall one of the GDC videos I watched the speaker referred to this setMain idea, but I cannot find it again. If anybody knows which video this was, that would be cool.
FYI, I went through this again https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test/README.md with the -test dependency in place, and it is now working. Thank you.