2017-07-03 70 views
0

我写春天批次application.Code JUnit的测试用例下面异常在JUnit的情况下实现了Spring Batch的

@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: {} 

请建议

+0

什么'Job'你期待执行? –

+0

嗨..我只有一个工作在我的春天批处理应用程序。但我不知道如何执行它在Junit.CanüPLZ告诉我 –

回答

1

这条线:

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

仅加载您的测试配置,但该配置不包含要测试的Job。您需要包括与classes阵列作业中的配置,例如:

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

+0

嗨..谢谢你的答复。我是新的春天batch.CanüPLZ告诉我如何以及在哪里添加作业配置。预先感谢 –

+0

当然@Programming_Geek,我更新了我的答案。让我知道它是否没有意义。 – ck1

+0

谢谢..它工作 –

相关问题