添加和提交命令的单元测试

时间:2021-07-12 16:59:11

标签: java junit mockito jgit

我在我的代码中使用 JGit 库来添加和提交新文件。但我不确定如何通过 Mockito 编写单元测试。

这是使用 JGit 设置存储库的模板。

private static final String PACKAGE_NAME = "ABC";
private static final String CLONED_REPO_PATH = String.format("/tmp/%s", PACKAGE_NAME);
final File gitFile = new File(String.join("/", CLONED_REPO_PATH, ".git"));
final Git openedRepo = Git.open(gitFile);

我想为这些特定语句编写单元测试:

  1. openedRepo.checkout().setCreateBranch(true).setName(branchName).call();
  2. openedRepo.add().addFilepattern(<some file>).call();
  3. openedRepo.commit().setMessage(commitMessage).call();

当我尝试使用此测试代码测试 [1](结帐分支步骤)时出现错误:
git.checkout().setCreateBranch(true).setName("test2").call();

<块引用>

Ref HEAD 无法解析

0 个答案:

没有答案