Mockito为“ verify()”抛出InvalidUseOfMatchersException异常

问题描述 投票:0回答:1

我想在我的应用程序中测试API调用。因为API调用是异步的。我正在使用模仿(verifyArgumentCaptor)。

@Captor
lateinit var callbackCaptor: ArgumentCaptor<Callback<ResponseModel>>

 @Test
 fun testDetailsApiCall() {
    val mock: MyRepository = mock()
    verify(mock.getSomeDetails("xxx", "xxx", capture(callbackCaptor)))
 }

getSomeDetails内部的[MyRepository正在调用服务器API并通过interface回调发送回响应。

但是执行此测试用例时,出现以下错误

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
3 matchers expected, 1 recorded:
-> at xxx.xxxx.testDetailsApiCall

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.

如果你们能解决这个问题,那将真的很有帮助

android asynchronous testing kotlin mockito
1个回答
1
投票

如果您要通过参数调用来验证某些方法,则将匹配器(例如any()eq()等)用于其[[all

© www.soinside.com 2019 - 2024. All rights reserved.