junit - org.mockito.exceptions.misusing.InvalidUseOfMatchersException:编写单元测试时
问题描述
当我想测试我的方法时,我得到了这个错误,我是单元测试的新手。无法找到确切的问题。打印test6
日志时,测试方法的倒数第二行似乎有错误。任何建议!
12 Jul 2021 13:51:54,915 [INFO ] (main) amazon.platform.config.AppConfigTree:1756: No appgroup found
test1
test2
test3
test4
test5
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
4 matchers expected, 3 recorded:
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.
这是我要测试的课程。
public String addCommitAndPushUntrackedChanges(final String deviceName, final List<String> filesList)
throws GitAPIException, IOException, DependencyFailureException {
final String tempCommitBranchName = String.format("Add Sync "
+ "rules : [%s]", deviceName);
final File gitFile = new File(String.join("/", CLONED_REPO_PATH, ".git"));
String CommitId = jgitAccessor.addAndCommitUntrackedChanges(gitFile, deviceName, tempCommitBranchName, filesList);
gitFarmServiceAccessor.loadTmpSshTicket();
jgitAccessor.pushToTemporaryBranch(gitFile, REPO_URI, deviceName);
return CommitId;
}
这是测试方法
@InjectMocks
CreateIngestionRulesTaskBuilder builder;
@Test
public void addCommitAndPushUntrackedChanges_happyCase() throws Exception {
System.out.println("test1");
Mockito.doNothing().when(gitFarmServiceAccessor).loadTmpSshTicket();
System.out.println("test2");
System.out.println("test3");
Mockito.doNothing().when(jgitAccessor).pushToTemporaryBranch(REPO_FILE, REPO_LOCATION,"abc");
System.out.println("test4");
when(jgitAccessor.addAndCommitUntrackedChanges(eq(REPO_FILE),eq(TEST_DEVICE_NAME),eq(TEST_COMMIT_MSG), anyList())).thenReturn(eq(TEST_COMMIT_ID));
System.out.println("test5");
builder.addCommitAndPushUntrackedChanges(any(), anyList());
System.out.println("test6");
}
解决方案
推荐阅读
- python - Pandas 从 Excel 读取时会更改数字
- java - 由于基础异常而无法加载连接类:com.mysql.cj.exceptions.WrongArgumentException
- reactjs - 福米克
如果使用 componentDidMount/setState,initialValue 未定义 - taskscheduler - 在管理员帐户下创建时间触发器 Windows 任务时访问被拒绝
- python - Ruby 等价于 Python chain()
- scala - typeclass 注释应该已被 simulacrum 删除,但没有
- swift - UINavigationbar 在返回时掩盖项目
- python - 解析具有多个同名子项的xml子项,python
- java - Java 流参数限制无限制(MongoDB 不一致)
- makefile - Makefile 与 Windows 资源文件的循环依赖关系