When I run my unit tests, it invokes my scheduled tasks. I want to prevent this behaviour, which is caused by the fact that I have @EnableScheduling on my main
In each Test you define which spring configuration should be used, currently you have:
@ContextConfiguration(classes={AppConfiguration.class})
Common practice is to define separate spring configuration for your normal application and for your tests.
AppConfiguration.java
TestConfiguration.java
Then in your test you simply refference TestConfiguration instead of your current AppConfiguration using @ContextConfiguration(classes={TestConfiguration.class})
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={TestConfiguration.class})
@Transactional
@TransactionConfiguration(defaultRollback = true)
@WebAppConfiguration
public class ExampleDaoTest
This way you can configure any setting for your tests differently than in production code. You can for example use in-memory database for your tests instead of regular one and much more.