我使用spring-starter-test和junit5,为了运行spring测试,我需要使用@ExtendWith
而不是@RunWith
。然而@IfProfileValue
适用于@RunWith(SpringRunner.class)
,但不适用于@ExtendWith(SpringExtension.class)
,以下是我的代码:
@SpringBootTest
@ExtendWith({SpringExtension.class})
class MyApplicationTests{
@Test
@DisplayName("Application Context should be loaded")
@IfProfileValue(name = "test-groups" , value="unit-test")
void contextLoads() {
}
}
因为它没有指定环境test-groups,所以应该忽略contextLoads。但是测试仍会运行并忽略@IfProfileValue
。
@EnabledIfSystemProperty
和@DisabledIfSystemProperty
支持。 - Sam Brannen