【问题标题】:org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 2 matchers expected, 1 recorded:org.mockito.exceptions.misusing.InvalidUseOfMatchersException:预期 2 个匹配器,记录 1 个:
【发布时间】:2021-09-24 20:20:07
【问题描述】:

代码:

Mockito.when(mongoRepo.findByIdAndIsDeleted(objId, false)).thenReturn(responseObj);
// here mongoRepo is MongoRepository and objId is UUID

当我运行测试用例时,出现以下异常:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 2 matchers expected, 1 recorded:

我也尝试了一些其他方法,但没有运气

我尝试的第二个例子:

Mockito.when(mongoRepo.findByIdAndIsDeleted(any(), anyBoolean())).thenReturn(responseObj);
// here mongoRepo is MongoRepository

我尝试的第三个例子:

 Mockito.when(mongoRepo.findByIdAndIsDeleted(any(UUID.class), Mockito.eq(false))).thenReturn(responseObj);
// here mongoRepo is MongoRepository

我遇到了同样的异常。 任何帮助将不胜感激!

我正在使用 MockitoJUnitRunner

【问题讨论】:

  • 请发布异常的完整堆栈跟踪,以及一个完整的、可运行的示例。

标签: java unit-testing junit mockito


【解决方案1】:

如果我没记错的话,Mokito 为这个错误提供了额外的解释,并在运行日志中打印了解释。 或者你可以检查一下 Matcher 方法是否被正确引用,一些同名的方法出于不同的目的返回 Matcher?

【讨论】:

    猜你喜欢
    • 2011-09-26
    • 2020-03-23
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多