spring-batch - 如何使用 Mockito 编写 Spring Batch 测试用例?
问题描述
我正在寻找为我编写测试用例Spring Batch Job
,为此我正在通过链接:https ://docs.spring.io/spring-batch/docs/4.0.x/reference/html/testing.html#creatingUnitTestClass我在测试用例下面开发,我意识到它实际上像真正的批处理作业调用一样工作,这可能是可悲的。
我想简单地模拟所有批处理作业。是否有任何 OOTB API 或者我可以简单地使用 Mockito 来制作它?
@SpringBatchTest
@SpringBootTest
@RunWith(SpringRunner.class)
public class Job {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@BeforeClass
public static void beforeClass() {
// set some env variables to allow Spring Context to load up !
}
@Test
public void test() throws Exception {
JobExecution jobExecution = this.jobLauncherTestUtils.launchJob();
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
}
}
解决方案
推荐阅读
- mongodb - 异常 Mongo Server 和 Meteor 查询不同意有多少文档与您的查询匹配
- docker - 在 Docker Windows 容器上运行 Traefik
- javascript - JavaScript 是如何工作的:在 V8 引擎内部?
- c++ - 在运行时创建 mfc c++ 控件
- google-apps-script - 如何将数组传递到 Google 电子表格的 Google App 脚本中的查询字符串
- reactjs - react native 使用新的生命周期进行动画
- forms - 通过 POST 方法将表单发送到 Wix 中的另一个 PHP 文件
- gdb - Trace32 命令从 ELF 文件中读取给定地址的符号名称
- python - Python将数组的值拆分为不同的列
- sql - 从 String 中获取特定值