I am working on a Spring Batch application that has two steps in a job. I am trying to test each step individually. According to Spring documentation, I should be able to do so using JobLauncherTestUitls.launchStep()
I have the following test set up for one of the steps
@SpringBootTest
@SpringBatchTest
@EnableAutoConfiguration
@ContextConfiguration(classes = {JobConfig.class, EmailAndArchiveStepConfig.class, UpdateFactorReserveConfig.class})
@ExtendWith(SpringExtension.class)
@ActiveProfiles("test")
class ConfigTest {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Test
@DisplayName("Testing Email and Archive Configured")
public void testEmailAndArchiveConfig(){
JobExecution jobExecution = jobLauncherTestUtils.launchStep("Email and Archive", executionContext);
assertEquals(new ExitStatus("COMPLETED").getExitCode() ,jobExecution.getExitStatus().getExitCode());
}
However, when I run this test, it starts the job from the beginning, running the other step as well, rather than just running this step that I want to test. I have not been able to find any solution to this.