我正在尝试将协程添加到我们的 Android 应用程序中,但我在使用我们的模拟框架时遇到了障碍。我的界面有一个暂停功能,如下所示:
interface MyInterface {
suspend fun makeNetworkCall(id: String?) : Response?
}
这是我尝试验证代码在我的单元测试中执行的方式
runBlocking {
verify(myInterface).makeNetworkCall(Matchers.anyObject())
}
当我这样做时,我收到以下错误
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
2 matchers expected, 1 recorded:
-> at com.myproject.MyTest$testFunction$1.invokeSuspend(MyTest.kt:66)
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"));
是否有另一种方法我们应该验证在使用协程时是否调用了适当的方法?任何帮助,将不胜感激。