Scenario -
Hi I am new in testing using mockk. I want to test the order in which methods are being called in viewmodel. And I want to test livedata.postValue
in verify
block{} but mockk is giving an exception. Kindly also help me to understand the meaing of exception
MyViewModel.kt
fun doWork(showError: Boolean = false) {
launch {
val result = getImageUseCase.getImages()
if (!showError) {
withContext(uiDispatcher) {
liveDataResponse.postValue(LiveDataResult.success(Response(result)))
}
} else {
throw Exception("Unknown")
}
}
}
MyViewModelTest.kt
@Test
fun verifyOrderOfMethodExecution(){
coEvery { getImageUseCase.getImages() } returns 1
myViewModel.doWork()
coVerifyOrder {
getImageUseCase.getImages()
myViewModel.liveDataResponse.postValue(any())
}
}
Exception -
io.mockk.MockKException: Failed matching mocking signature for
SignedCall(retValue=, isRetValueMock=true, retType=class kotlin.Any, self=GetImageUseCase(usecase#1), method=getImages(Continuation), args=[Continuation at com.rahullohra.lab.MyViewModelTest$verifyOrderOfMethodExecution$2.invokeSuspend(MyViewModelTest.kt:79)], invocationStr=GetImageUseCase(usecase#1).getImages(continuation {}))
left matchers: [any()]