我想在春天測試禁用@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