Testing coroutines in the presenter class
I found a solution for that: following this tutorial, I've setup both
@Before
fun setup() {
Dispatchers.setMain(Dispatchers.Unconfined)
...
}
@After
fun tearDown() {
Dispatchers.resetMain() // reset main dispatcher to the original Main dispatcher
}
And by running the entire launch block of the presenter
class inside a runBlocking
statement in the test. The problem was related also to a not reported exception inside the suspended function that was actually not mocked but it was invisible to my eyes.
Now everything is working fine.