Spring批处理的junit案例实现中的异常

Spring批处理的junit案例实现中的异常,spring,exception,junit,spring-batch,Spring,Exception,Junit,Spring Batch,我正在为spring批处理应用程序编写junit测试用例 @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = { AppTest.BatchTestConfig.class }) public class AppTest { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; @Test public void

我正在为spring批处理应用程序编写junit测试用例

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { AppTest.BatchTestConfig.class })
public class AppTest {

    @Autowired
    private JobLauncherTestUtils jobLauncherTestUtils;

    @Test
    public void demo() throws Exception {
        JobExecution jobExecution = jobLauncherTestUtils.launchJob();

        Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    }

    @Configuration
    @EnableBatchProcessing
    static class BatchTestConfig {

        @Bean
        JobLauncherTestUtils jobLauncherTestUtils() {
            return new JobLauncherTestUtils();
        }

    }
}
但以下给出的例外情况也是如此:

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.NoSuchBeanDefinitionException: 
No qualifying bean of type 'org.springframework.batch.core.Job' available: 
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
请建议这一行:

@SpringBootTest(classes={AppTest.BatchTestConfig.class})

仅加载测试配置,但该配置不包含要测试的
作业。您需要在
数组中包含作业的配置,例如:


@SpringBootTest(类={AppTest.BatchTestConfig.class,MyJobConfig.class})

您希望执行什么
作业
吗?嗨..我的spring batch应用程序中只有一个作业。但是我不知道如何在Junit中执行它。请告诉我..谢谢你的回复。我是spring batch的新手。请告诉我如何以及在哪里添加作业配置。提前感谢@Programming\u Geek,我更新了我的答案。如果没有道理,请告诉我。