How to make Spring Boot Test
under JUnit 5
resolve indented/hierarchical properties externalized on a YAML file?
I would like to write tests to validate some logic that depends on 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));
}
}
}
The dotted.hierarchical.property
property is defined on the application-test.yml
YAML file like this:
dotted:
hierarchical:
property: application-test.yml
The test case fails with the property evaluating to null
. I am locked to spring-boot 1.5.8.RELEASE, so I am using org.springframework.test:spring-test-junit5. I created a Gist with the full example.