其他分享
首页 > 其他分享> > 是否可以在集成测试期间禁用Spring的@Async?

是否可以在集成测试期间禁用Spring的@Async?

作者:互联网

我有一个用@Async注释的方法说

@Async
public void createArticles(long Id){}

但我只是尝试对该方法进行黄瓜测试.是否可以同步测试?

解决方法:

创建异步配置类:

@Configuration
@EnableAsync
@ConditionalOnProperty(name = "async.enabled", havingValue = "true")
public class SpringAsyncConfig {
    // Your configuration here
}

如果仅配置值async.enabled为true,则注释@ConditionalOnProperty将创建此bean

然后在配置文件中,如果要运行集成测试,可以将值设置为false

async.enabled = false

或者,如果您使用的是Spring配置文件,则可以始终在其他配置文件配置文件中将值设置为true,例如application.properties,application-dev,并在application-integration.properties中设置为false.

标签:spring,cucumber-java
来源: https://codeday.me/bug/20190706/1392369.html