此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 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 性能。 |
有关示例和更多详细信息,请参阅使用测试属性源进行上下文配置。