【发布时间】:2016-12-07 10:58:54
【问题描述】:
我正在尝试测试 Spring Batch 步骤。我有 2 个场景要测试 1. 使用 tasklet 步骤(步骤范围) 2. Step with ItemReader/ItemWriter (step scope)
我的测试类注释如下
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class})
@ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = ItemReturnsApplication.class)
This is how my test class looks like
@Bean
JobLauncherTestUtils jobLauncherTestUtils(){
return new JobLauncherTestUtils();
}
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
public void testLaunchJob() throws Exception{
JobExecution jobExecution = jobLauncherTestUtils.launchJob(
new JobParametersBuilder().addString("chunkSize", "3").addString("current_date","2016-11-25").toJobParameters()
);
commonAssertions(jobLauncherTestUtils.launchJob());
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
}
当我运行测试用例时,该过程失败,因为作业参数没有传递到我的作业中。
我正在寻找在 Spring Batch 中测试 Step Scoped 步骤的正确方法。
谢谢, 开源浏览器
【问题讨论】:
标签: spring-batch