如何在Spring Boot中基于配置文件运行/关闭选择性测试 [英] how to run/turn off selective tests based on profiles in spring boot
本文介绍了如何在Spring Boot中基于配置文件运行/关闭选择性测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个正在为其编写IT测试的spring-boot
应用程序.
当我激活dev
配置文件时,测试数据来自application-dev.properties
这是我要进行的测试:
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class ApplicationTests {
@Autowired
Environment env;
@Test
public void contextLoads() {
System.out.println(Arrays.toString((env.getActiveProfiles())));
}
}
ServiceITTest
public class ServiceITTest extends ApplicationTests {
@value
String username;
@value
String address;
@Autowired
MyService myService;
@Test
public void check_for_valid_username_address(){
myService.validate(username,address);
}
}
我希望仅在设置概要文件"dev","qa"时运行上述测试.默认情况下,它不应运行.
在春季启动测试中能否获得良好的控制?
解决方案
您可能要使用@IfProfileValue
批注.不幸的是,它不能直接在活动配置文件上运行,而是可以读取属性,因此,如果您仅在要运行测试的配置文件中定义特定属性,则可以在该特定属性上使用该注释. >
查看全文