title: Disable @EnableScheduling on Spring Tests
body: <p>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 <code>@EnableScheduling</code> on my main app configuration.</p>
  
  <p>How can I disable this on my unit tests?</p>
  
  <p>I have come across this <a href="https://stackoverflow.com/questions/21490617/spring-3-2-disable-cacheable-during-unit-tests">question/answer</a> which suggests setting up profiles?  </p>
  
  <p>Not sure how I would go about that?  or if its an overkill?  I was thinking of having a separate AppConfiguration for my unit tests but it feels like im repeating code twice when I do that?</p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories(AppConfiguration.DAO_PACKAGE)
  @EnableTransactionManagement
  @EnableScheduling
  @ComponentScan({AppConfiguration.SERVICE_PACKAGE,
                  AppConfiguration.DAO_PACKAGE,
                  AppConfiguration.CLIENT_PACKAGE,
                  AppConfiguration.SCHEDULE_PACKAGE})
  public class AppConfiguration {
  
      static final    String MAIN_PACKAGE             = "com.etc.app-name";
      static final    String DAO_PACKAGE              = "com.etc.app-name.dao";
      private static  final  String ENTITIES_PACKAGE  = "com.etc.app-name.entity";
      static final    String SERVICE_PACKAGE          = "com.etc.app-name.service";
      static final    String CLIENT_PACKAGE           = "com.etc.app-name.client";
      static final    String SCHEDULE_PACKAGE         = "com.etc.app-name.scheduling";
  
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
         // stripped code for question readability
      }
  
      // more app config code below etc
  
  }
  </code></pre>
  
  <p>Unit test example.</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes={AppConfiguration.class})
  @Transactional
  @TransactionConfiguration(defaultRollback = true)
  @WebAppConfiguration
  public class ExampleDaoTest {
  
      @Autowired
      ExampleDao exampleDao;
  
      @Test
      public void testExampleDao() {
          List&lt;Example&gt; items = exampleDao.findAll();
          Assert.assertTrue(items.size()&gt;0);
      }
  }
  </code></pre>