对于最新的稳定版本,请使用 Spring Framework 6.2.0! |
@TestPropertySource
@TestPropertySource
是类级注解,可用于配置
要添加到PropertySources
在Environment
对于ApplicationContext
loaded 为
集成测试。
下面的示例演示了如何从 Classpath 声明属性文件:
-
Java
-
Kotlin
@ContextConfiguration
@TestPropertySource("/test.properties") (1)
class MyIntegrationTests {
// class body...
}
1 | 从以下位置获取属性test.properties 在 Classpath 的根目录中。 |
@ContextConfiguration
@TestPropertySource("/test.properties") (1)
class MyIntegrationTests {
// class body...
}
1 | 从以下位置获取属性test.properties 在 Classpath 的根目录中。 |
下面的示例演示如何声明内联属性:
-
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 性能。 |