如何在 YAML 文件上解析缩进/分层属性Spring Boot Test?JUnit 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)