Hi guys, coroutines are awesome 馃憤
I just started a new multiplatform library project which is based on coroutines, but I have trouble figuring out how I am supposed to write tests using coroutines.
Since most code is in the 'commonMain' sourceSet I would like to write tests for my suspending functions there. Because Kotlin's @Test annotation does not support suspending tests and 'runBlocking' is not available in the common module of coroutines, I do not see how I could test those suspending functions in the commonTest module. Did I miss something here?
Thanks in advance 鈽猴笍
runBlocking is not present in the common package because JS platform does not support it.
In my experience, I had to make a common function runTest that calls runBlocking on JVM and Native and that use Promise on Node.js (as most Node.js test libraries handle correctly test cases that return a Promise it works just fine)
Here are the links to my implementations
Hope this helps
In my experience, I had to make a common function runTest that calls runBlocking on JVM and Native and that use Promise on Node.js
This is more or less the thing we do in our tests (+ custom CoroutineExceptionHandler and catch in promise to fail a test on exception)
Thanks a lot guys! 鈽猴笍
What about Native implementation? :/
I intentionally omit native implementation because it contains library specific functions but it works exactly like JVM as it implements runBlocking
Most helpful comment
runBlocking is not present in the common package because JS platform does not support it.
In my experience, I had to make a common function
runTestthat callsrunBlockingon JVM and Native and that usePromiseon Node.js (as most Node.js test libraries handle correctly test cases that return aPromiseit works just fine)Here are the links to my implementations
Hope this helps