小编the*_*iro的帖子

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

如何在 YAML 文件上解析缩进/分层属性Spring Boot TestJUnit 5

我想编写测试来验证一些依赖于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));
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

dotted.hierarchical.property属性在 YAML 文件中定义application-test.yml如下:

@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"; …
Run Code Online (Sandbox Code Playgroud)

java spring-boot junit5 spring-boot-test

6
推荐指数
0
解决办法
547
查看次数

标签 统计

java ×1

junit5 ×1

spring-boot ×1

spring-boot-test ×1