Am experiencing some issue with writing coroutine...
# coroutines
n
Am experiencing some issue with writing coroutine test and I'm in need of help. So here is the situation, I have 2 different coroutine test classes that pass when I run them individually but when I run the entire tests in the package one passes wile the other fails.
To provide more scope I'm injecting the coroutine test scope
l
not enough information
l
Hey! It sounds like a frustrating problem! I'm assuming you are using
runBlockingTest
? Are you also passing in
TestCoroutineDispatcher
instead of using something like
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
? Those are the two issues I've bumped into with tests of coroutines. Apart from that it would help if you could provide us with more detailed information on what is going wrong 🙂
n
Thanks @Luke Sleeman for your response, to provide more scope to the issue here is the link to my test file https://github.com/ellykits/neat-form/blob/master/neat-form-core/src/test/java/com/nerdstone/neatformcore/robolectric/rules/NeatFormValidatorTest.kt
So I have a a class called JsonFormBuilder that parses Json in using the
Dispatcher.Default
scope then using the parsed model, I create views on the main thread. Then I have the
NeatFormValidator
class that validates the data entered on the views before submitting the form. I was writing test for the validator class when I encountered the issues mentioned above.
And yes am using
TestCoroutineDispatcher
for my test classes. And just to give more details on the projects background: the library allows you to create views from json; parses the json into a model, register form rules for handling skip logic and calculations, creates the view (all this done on the `JsonFormBuilder`class using coroutines) with different contexts (Default, IO and Main) respectively. The validator class is a singleton instance of the
JsonFormBuilder
l
Thanks for the detailed info! Unfortunately I’m finishing up work for the day at the moment. Hopefully somebody in a different timezone can give you some suggestions 🤞 . Otherwise I’ll try and have a quick look tomorrow and see if anything strikes me as odd. Unfortunately I’m just starting to learn this stuff as well 😬
n
Cool @Luke Sleeman your feedback is much appreciated