I am trying to test the Spring Batch steps. I have 2 scenarios to test 1. Step with tasklet (step scoped) 2. Step with ItemReader/ItemWriter (step scope)
My test class is annotated as follows
@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());
}
When I run the test case, the process fails because the the job parameters are not getting passed into my job.
I am looking for the right way of testing the Step Scoped steps in spring batch.
Thanks, Opensource Explorer