2016-02-05 107 views
1

我正在爲Spring引導批次編寫Junit測試。 在我的JUnit我希望啓動與此一步:使用@SpringApplicationConfiguration進行JUnit測試自動啓動作業

JobExecution jobExecution = jobLauncherTestUtils.launchStep("y"); 

我的JUnit類anotated與theese:

@SpringApplicationConfiguration(classes = { MyBatchConfiguration.class }) 
@RunWith(SpringJUnit4ClassRunner.class) 

我的問題是,測試甚至什麼也沒有內部的測試方法,發射我所有的批處理作業都是以正常方式啓動的。 這裏是我的BatchConfFile註釋

@Configuration 
@EnableBatchProcessing 
@EnableAutoConfiguration 
@ConditionalOnClass({ JobLauncher.class }) 
@ComponentScan({ "toto" }) 

和作業通過我的測試:(自動啓動

@Bean 
public Job MyJob(@Qualifier("x") Step x, 
@Qualifier("y") Step y) { 

     return jobs.get("j").incrementer(new DateJobIncrementer()).start(x).next(y).build(); 
    } 

回答

3

就與此內容創建src/test/resources/application.properties文件:

spring.batch.job.enabled=false # Do not execute all Spring Batch jobs in the context on startup.