Java 如何在JUnit 5下进行Spring引导测试,以解决YAML文件上外部化的缩进/分层属性
如何在Java 如何在JUnit 5下进行Spring引导测试,以解决YAML文件上外部化的缩进/分层属性,java,spring-boot,junit5,spring-boot-test,Java,Spring Boot,Junit5,Spring Boot Test,如何在JUnit 5下进行Spring启动测试解决YAML文件上外部化的缩进/分层属性? 我想编写测试来验证一些逻辑,这取决于: dottered.hierarchy.property属性在application test.ymlYAML文件中定义如下: 虚线: 层次结构: 属性:application-test.yml 测试用例失败,属性评估为null。我已锁定到spring boot 1.5.8.RELEASE,因此我正在使用。我创建了一个 @ExtendWith(SpringExtens
JUnit 5
下进行Spring启动测试
解决YAML文件上外部化的缩进/分层属性?
我想编写测试来验证一些逻辑,这取决于:
dottered.hierarchy.property
属性在application test.yml
YAML文件中定义如下:
虚线:
层次结构:
属性:application-test.yml
测试用例失败,属性评估为null
。我已锁定到spring boot 1.5.8.RELEASE,因此我正在使用。我创建了一个
@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));
}
}
}