我想在春天测试禁用@Schedule但我不能老是找到一个方法来做到这一点。禁用春@EnableScheduling在JUnit测试
我试图让不同的配置类测试环境,但任务仍然被解雇。 这是配置:
@Configuration
@EnableTransactionManagement
@EnableScheduling
@ComponentScan({"de.package"})
@PropertySource(name="application.properties", value="classpath:application.properties")
public class PersistenceJPAConfig {
...
}
这是测试emvironment config.Just去除@EnableScheduling注释
@Configuration
@EnableTransactionManagement
@ComponentScan({"de.package"})
@PropertySource(name="application.properties", value="classpath:application.properties")
public class PersistenceJPATestConfig {
...
}
在测试我使用:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { PersistenceJPATestConfig.class }, loader = AnnotationConfigContextLoader.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GetArticlesTest {
...
}
但是当我运行的任务仍然解雇测试..有没有办法在运行测试时停止执行任务?
[春试验禁用@EnableScheduling]的可能的复制(http://stackoverflow.com/questions/29014496/disable-enablescheduling-on-spring-tests) – ali