将其与代码段进行比较:
val mock = mock<MutableLiveData<UUID>> { on { value } doReturn y }
`when`(x).thenReturn(mock)
和
`when`(x).thenReturn(mock<MutableLiveData<UUID>> { on { value } doReturn y })
为什么第一个代码片段可以正常工作,而第二个代码片段内嵌模拟,为什么会抛出org.mockito.exceptions.misusing.UnfinishedStubbingException?
Mockito错误消息:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at com.xxx.android.ClassTest$testName$1.invokeSuspend(ClassTest.kt:579)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, which is not supported
3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed
Mockito版本2.22.0, Kotlin版本1.3.31