如何在JUnit 5下进行Spring Boot Test来解决在YAML文件上外部化的缩进/分层属性

问题描述

如何使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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...