问题描述
如何使Spring Boot Test
下的JUnit 5
解决在YAML文件上外部化的缩进/分层属性?
我想编写测试来验证一些依赖于Environment.getProperty(String key)的逻辑:
@ExtendWith(SpringExtension.class)
class PropertiesReolution_SO_IT {
@Nested
@TestPropertySource(locations = "classpath:application-test.yml")
public class ViaYamlFile {
@Autowired
private Environment env;
@Test
void testGetDottedHierarchicalProperty() throws Exception {
final String key = "dotted.hierarchical.property";
assertNotNull(this.env.getProperty(key));
assertEquals("application-test.yml",this.env.getProperty(key));
}
}
}
dotted.hierarchical.property
属性是在application-test.yml
YAML文件上定义的,如下所示:
dotted:
hierarchical:
property: application-test.yml
测试用例失败,其属性评估为null
。我被锁定为spring-boot 1.5.8.RELEASE,所以我正在使用org.springframework.test:spring-test-junit5。我创建了Gist with the full example。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)