Marek Kubiczek
07/14/2022, 9:07 AM@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?ephemient
07/14/2022, 9:50 AMMarek Kubiczek
07/14/2022, 9:55 AMUnhandled exceptions will be thrown at the end of the test. If the uncaught exceptions happen after the test finishes, the error is propagated in a platform-specific manner. If the test coroutine completes with an exception, the unhandled exceptions are suppressed by it.that’s the case here right?
ephemient
07/14/2022, 10:04 AM