unit-testing - 方法抛出 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' 异常。
问题描述
我正在尝试测试此方法,但是出现以下错误:
Method threw 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' exception.
在这行代码上:
when(tester.method(
any(String.class), any(LocalDate.class), any(boolean.class),any(boolean.class), any(String.class))).thenReturn(item);
解决方案
对于您使用的大多数类型,已经有内置的匹配器。
when(tester.method(anyString(), any(LocalDate.class), anyBoolean(),anyBoolean(), anyString()))
.thenReturn(item);
对于原始类型,请使用
any{Type}()
族。
推荐阅读
- python - 在 Python 中,如何让这个模型检查 PC 的音频输出流
- git - 将 Github Git 存储库迁移到 Azure DevOps TFVC
- r - 将NA值替换为“NA”后,所有值的数据类型已转换为字符
- javascript - 从日期值中提取月份
- css - Vue js计算属性不更新渐变文本
- powerapps - 允许文件选择的 Powerapps Explorer 对话框
- php - 如何使用 PHP 将字符串变量传递给 SQL 查询
- jboss - 防止外部访问 jboss 中的一个服务器组?
- python - 查找具有特定文本 selenium python 的所有元素
- azure-data-explorer - Kusto 中的累积产品