0

I would like to disable "Spring Scheduling" in Spring Boot Tests. Is there any simple way? I was trying to find something... but I have not been successful.

Thank you.

Application.java

@EnableAutoConfiguration
@EnableScheduling
@SpringBootApplication
public class Application {

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

}

ProductionService.java

@Component
public class ProductionService {
  @Scheduled(fixedRate = 1)
  public void printName() {
    System.out.println("-----PRINT NAME-----");
  }
}

TestClass.java

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestClass {
}

If I run tests in the TestClass, I get a lot of rows with -----PRINT NAME-----. I know, that configuration for @SpringBootTest is taken from @SpringBootApplication (in default setting). But my question is.. How can I disable scheduling in spring boot tests. Of course I can use separate configuration, but I have supposed there is a better and easier way how to do it. Something lika @EnableScheduling(enable=false)

Thank you.

TomasB
  • 11
  • 4
  • There's also the `@Profile` option: [Disable Spring @EnableScheduling in Junit tests](http://stackoverflow.com/questions/39033456/disable-spring-enablescheduling-in-junit-tests) – Sotirios Delimanolis Dec 12 '16 at 16:43
  • I know about that... but I have wanted to avoid the profile.. basically it means to modify application code. I finally decided to create new configuration in the tests. But I still think to have option to override scheduling would be nice. Thank you. – TomasB Dec 14 '16 at 08:58

0 Answers0