I am testing viewModel using the new coroutines testing framework and Mockk library. It seems that the exceptions from child coroutines are swallowed though.
It looks more or less like this example:
@Before
fun setUp() {
Dispatchers.setMain(UnconfinedTestDispatcher())
}
@Test
fun `Some exemplary test`() = runTest {
val dependency1 = mockk<Dependency1>()
val viewModel = TestedViewModel(dependency1)
viewModel.testedMethod()
coVerify(exactly = 1) { dependency1.methodToBeCaled() }
}
The ViewModel itself is calling that method in viewModelScope
fun testedMethod() {
viewModelScope.launch {
methodToBeCalled()
}
}
However I forgot to mock the called method. I am seeing in log
Exception in thread "Test worker @coroutine#7" io.mockk.MockKException: no answer found for: Dependency1(#1).methodToBeCalled(continuation {})
But the test passes.
Is it known issue?