I am trying to write Integration test for spring batch aplication , in my project there are approx 10+jobs I want to run only a single job but unable to achieve any Suggestion.
@SpringBatchTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes= MyApp.class)
@SpringBootTest
@Slf4j
public class JobATest {
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
@Autowired
@Qualifier(JOB_A)
Job joba;
@Before
public void setUp() throws Exception {
log.debug("CAME HERE setUp {} ",joba.getName());
jobLauncherTestUtils.setJob(joba);
}
@After
public void tearDown() throws Exception {
}
@Test
public void processAJob() throws Exception {
jobLauncherTestUtils.launchJob();
}
}
ERROR
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'jobLauncherTestUtils': Unsatisfied dependency expressed
through method 'setJob' parameter 0; nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type 'org.springframework.batch.core.Job' available:
expected single matching bean but found 2: **joba,jobb**
When using
@SpringBatchTest
, it is expected that the test context contains a single job bean. This is mentioned in the javadoc of the annotation.There is an open issue for that which we might consider for the next major release. Please upvote or add a comment if you have a suggestion for an improvement. I also invite you to check the thread on Multiple Job unit testing with @SpringBatchTest which could help you as well.