https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

tylerwilson

06/24/2019, 6:28 PM
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

tylerwilson

06/24/2019, 8:09 PM
I only see a DateTest in the common text folder, and no coroutines tests. Not in the Android test area.
e

elizarov

06/24/2019, 8:44 PM
What kind of common test you are looking to write?
r

ribesg

06/25/2019, 6:35 AM
You can only easily test coroutines on the JVM right now...
t

tylerwilson

06/26/2019, 3:20 PM
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.
4 Views