@ActiveProfiles
@ActiveProfiles
@ActiveProfiles 是一个可以应用于测试类的注解,用于声明在为集成测试加载 ApplicationContext 时应该激活哪些 bean 定义配置文件。
以下示例表明 dev 配置文件应该处于活动状态:
- Java
- Kotlin
@ContextConfiguration
@ActiveProfiles("dev") 1
class DeveloperTests {
// class body...
}
表示
dev配置文件应该是激活的。
@ContextConfiguration
@ActiveProfiles("dev") 1
class DeveloperTests {
// class body...
}
表示
dev配置文件应该是激活的。
以下示例表明 dev 和 integration 配置文件都应该处于活动状态:
- Java
- Kotlin
@ContextConfiguration
@ActiveProfiles({"dev", "integration"}) 1
class DeveloperIntegrationTests {
// class body...
}
表示
dev和integration配置文件应该是激活的。
@ContextConfiguration
@ActiveProfiles(["dev", "integration"]) 1
class DeveloperIntegrationTests {
// class body...
}
表示
dev和integration配置文件应该是激活的。
备注
@ActiveProfiles 默认提供对由超类和封闭类声明的活动 bean 定义配置文件的继承支持。您还可以通过实现自定义的 ActiveProfilesResolver 并使用 @ActiveProfiles 的 resolver 属性进行注册,程序matically 解析活动 bean 定义配置文件。
请参见 上下文配置与环境配置文件、@Nested 测试类配置 和 @ActiveProfiles 的 javadoc 以获取示例和更多详细信息。