【发布时间】:2018-07-12 06:01:54
【问题描述】:
考虑以下示例:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
"some.property=valueA"
})
public class ServiceTest {
@Test
public void testA() { ... }
@Test
public void testB() { ... }
@Test
public void testC() { ... }
}
我正在使用SpringBootTest 注释的properties 属性为该测试套件中的所有测试设置some.property 属性值。现在我想在不影响其他测试的情况下为其中一个测试(比如说testC)设置此属性的另一个值。我怎样才能做到这一点?我已经阅读了"Testing" chapter of Spring Boot docs,但没有找到任何符合我用例的内容。
【问题讨论】:
-
如果只需要配置几个属性,可以使用新的@DynamicPropertySource 注解。 stackoverflow.com/a/60941845/8650621
标签: java spring spring-boot