Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing without 'runBlocking' #885

Closed
sellmair opened this issue Dec 12, 2018 · 5 comments
Closed

Testing without 'runBlocking' #885

sellmair opened this issue Dec 12, 2018 · 5 comments
Labels

Comments

@sellmair
Copy link
Member

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 ☺️

@SeekDaSky
Copy link

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

@qwwdfsad
Copy link
Contributor

qwwdfsad commented Dec 12, 2018

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)

@sellmair
Copy link
Member Author

Thanks a lot guys! ☺️

@fardavide
Copy link

What about Native implementation? :/

@SeekDaSky
Copy link

I intentionally omit native implementation because it contains library specific functions but it works exactly like JVM as it implements runBlocking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants