I have a Spring Boot Application with the following (simplified) configuration class
@ConfigurationProperties(prefix = "prefix")
@Configuration
public class ConfigProperties {
@NotNull
public Duration snapshotOffset;
}
My code is working, but I would like know how I can write unit tests for the binding process with different property files as input?
You can configure test properties files by using the locations
or value
attribute of the TestPropertySource
annotation:
//Typically, @TestPropertySource will be used in conjunction with @ContextConfiguration.
@ContextConfiguration
@TestPropertySource("/test.properties")
public class Test {
// class body...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.