Scheduled method is called during the tests : <p>I'm developing a SpringBoot application using Maven. </p>

<p>I've a class with the <code>@Component</code> annotation which has a method <code>m</code> with the <code>@Scheduled(initialDelay = 1000, fixedDelay = 5000)</code> annotation. Here <code>fixedDelay</code> can be set to <em>specify the interval between invocations measured from the completion of the task</em>. </p>

<p>I've also the <code>@EnableScheduling</code> annotation in the main class as:</p>

<pre><code>@SpringBootApplication
@EnableScheduling
public class FieldProjectApplication {

    public static void main(String[] args) {
        SpringApplication.run(FieldProjectApplication.class, args);
    }

}
</code></pre>

<p>Now whenever I run the tests, defined as :</p>

<pre><code>@RunWith(SpringRunner.class)
@SpringBootTest
public class BankitCrawlerTests {

...

}
</code></pre>

<p>the scheduled task <code>m</code> is also run every 5 seconds.</p>

<p>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)?</p>
