我有两个配置文件:dev 和 default。当 Activity 配置文件为默认时,我想跳过一些(不是全部)测试。 是否有可能以某种方式标记这些测试?或者如何实现? 我用的是 Spring Boot 。这是我的父测试类:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyServiceStarter.class, webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT,
properties = {"flyway.locations=filesystem:../database/h2", "server.port=9100", "spring.profiles.default=dev"})
@Category(IntegrationTest.class)
public abstract class AbstractModuleIntegrationTest { ... }
最佳答案
我的同事找到了一个解决方案:
因此,如果您需要注释单独的测试,您可以使用 @IfProfileValue
注释:
@IfProfileValue(name ="spring.profiles.active", value ="default")
@Test
public void testSomething() {
//testing logic
}
此测试仅在默认配置文件处于 Activity 状态时运行
更新: 对于 Junit 5 使用:
@EnabledIfSystemProperty(named = "spring.profiles.active", matches = "default")
关于java - 是否可以标记 springboot 测试,以便它们仅在某些配置文件处于 Activity 状态时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43851621/