1

我试图测试一个具有高阶函数作为属性的方法,我遇到了这个问题:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at com.nhaarman.mockitokotlin2.KArgumentCaptor.capture(ArgumentCaptor.kt:198)

This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));

For more info see javadoc for Matchers class.

argumentCaptor<() -> Unit>()在另一个项目中使用,我不知道为什么这个应用程序会出现这个错误。

这是我的测试

@Test
fun onStart_fetchMovies_failed() {
    //Arrange
    val captor = argumentCaptor<() -> Unit>()
    `when`(movieDataSourceMock.movies(1)).thenReturn(Single.error(RuntimeException(ERROR_MESSAGE)))
    //Act
    SUT.onStart()
    //Assert
    verify(viewContractMock).showLoading()
    verify(viewContractMock).showMessageError(ERROR_MESSAGE, captor.capture())
    verify(viewContractMock).hideLoading()
}
4

0 回答 0