简体   繁体   中英

Spring Batch Test Single Job

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM