I'm developing a SpringBoot application using Maven.
I've a class with the @Component
annotation which has a method m
with the @Scheduled(initialDelay = 1000, fixedDelay = 5000)
annotation. Here fixedDelay
can be set to specify the interval between invocations measured from the completion of the task.
I've also the @EnableScheduling
annotation in the main class as:
@SpringBootApplication
@EnableScheduling
public class FieldProjectApplication {
public static void main(String[] args) {
SpringApplication.run(FieldProjectApplication.class, args);
}
}
Now whenever I run the tests, defined as :
@RunWith(SpringRunner.class)
@SpringBootTest
public class BankitCrawlerTests {
...
}
the scheduled task m
is also run every 5 seconds.
Of course I just want to run the scheduled task whenever the application runs. How can I do it (i.e. prevent the scheduled task to run when a test is run)?