|
对于最新的稳定版本,请使用 Spring Framework 6.2.10! |
@TestPropertySource
@TestPropertySource是一个类级注解,可用于配置
要添加到PropertySources在Environment对于ApplicationContext加载
集成测试。
以下示例演示了如何从类路径声明属性文件:
-
Java
-
Kotlin
@ContextConfiguration
@TestPropertySource("/test.properties") (1)
class MyIntegrationTests {
// class body...
}
| 1 | 从test.properties在类路径的根目录中。 |
@ContextConfiguration
@TestPropertySource("/test.properties") (1)
class MyIntegrationTests {
// class body...
}
| 1 | 从test.properties在类路径的根目录中。 |
以下示例演示如何声明内联属性:
-
Java
-
Kotlin
@ContextConfiguration
@TestPropertySource(properties = { "timezone = GMT", "port: 4242" }) (1)
class MyIntegrationTests {
// class body...
}
| 1 | 宣timezone和port性能。 |
@ContextConfiguration
@TestPropertySource(properties = ["timezone = GMT", "port: 4242"]) (1)
class MyIntegrationTests {
// class body...
}
| 1 | 宣timezone和port性能。 |
有关示例和更多详细信息,请参阅使用测试属性源进行上下文配置。