java - 添加和提交命令的单元测试
问题描述
我在我的代码中使用 JGit 库来添加和提交新文件。但我不确定如何通过 Mockito 编写单元测试。
这是使用 JGit 设置 repo 的模板。
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);
我想为这些特定语句编写一个单元测试:
openedRepo.checkout().setCreateBranch(true).setName(branchName).call();
openedRepo.add().addFilepattern(<some file>).call();
openedRepo.commit().setMessage(commitMessage).call();
当我尝试使用此测试代码测试 [1](结帐分支步骤)时出现错误:
git.checkout().setCreateBranch(true).setName("test2").call();
Ref HEAD 无法解决
解决方案
推荐阅读
- python - 用opencv python删除背景
- python-3.x - 基于条件在python中对列表中的元素进行重新排序
- reporting-services - 按多个字段分组,但按顺序排列
- operating-system - 什么是 1920x1080x24bpp OS Dev 的标准 VESA 视频模式
- javascript - 在nodejs 4.x中从不同文件位置重用异步函数的有效方法是什么?
- omnet++ - omnet++ 中多个 adhoc 节点之间使用 inet 进行无线通信
- ios - 使用 Turicreate 进行 iOS 人脸识别
- angular - Angular 6 CLI 不会将库的 assets 文件夹复制到 dist 文件夹中
- intellij-idea - Intellij/Webstorm Yarn - 除非在根目录下,否则无法找到包
- css - 如果同级列不存在,则使列跨度全宽