bodtx
bodtx

Reputation: 609

JUnit test with @SpringApplicationConfiguration start automatically the Job

I'm writing a Junit test for a spring boot batch. In my JUnit I want to launch a step with this:

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

My JUnit class is anotated with theese:

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

My problem is that the test even with nothing inside the test method, launch all my batch job as it was launched in the normal way. Here are the annotation on my BatchConfFile

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

and the Job automatically launched by my test :(

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

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

Upvotes: 1

Views: 941

Answers (1)

luboskrnac
luboskrnac

Reputation: 24561

Just create src/test/resources/application.properties file with this content:

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

Upvotes: 4

Related Questions