跳到主要内容
版本:7.0.3

@TestPropertySource

Hunyuan 7b 中英对照 @TestPropertySource @TestPropertySource

@TestPropertySource 是一个注解,可以应用于测试类,用于配置属性文件的位置以及内联属性,这些属性将会被添加到在集成测试中加载的 ApplicationContextEnvironment 中的 PropertySources 集合中。

以下示例演示了如何从类路径中声明一个属性文件:

@ContextConfiguration
@TestPropertySource("/test.properties") 1
class MyIntegrationTests {
// class body...
}
  • 从类路径根目录下的test.properties文件中获取属性。

以下示例演示了如何声明内联属性:

@ContextConfiguration
@TestPropertySource-properties = { "timezone = GMT", "port: 4242" }) 1
class MyIntegrationTests {
// class body...
}
  • 声明 timezoneport 属性。

有关示例和更多详细信息,请参阅使用测试属性源进行上下文配置