2017-07-03 73 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

謝謝..它工作 –

相關問題