@TestPropertySource
@TestPropertySource是一个注解,可以应用于测试类来配置
要添加到PropertySources在Environment对于ApplicationContextloaded 为
集成测试。
下面的示例演示了如何从 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性能。 |