@ActiveProfiles
@ActiveProfiles
是可以应用于测试类以声明当加载用于集成测试的 ApplicationContext
时应激活哪些 bean 定义配置文件的注解。
@ActiveProfiles
is an annotation that can be applied to a test class to declare which
bean definition profiles should be active when loading an ApplicationContext
for an
integration test.
以下示例表明应激活 dev
配置文件:
The following example indicates that the dev
profile should be active:
- Java
-
@ContextConfiguration @ActiveProfiles("dev") (1) class DeveloperTests { // class body... }
1 | Indicate that the dev profile should be active.
|
2 | Indicate that the dev profile should be active. |
以下示例表明应激活 dev
和 integration
配置文件:
The following example indicates that both the dev
and the integration
profiles should
be active:
- Java
-
@ContextConfiguration @ActiveProfiles({"dev", "integration"}) (1) class DeveloperIntegrationTests { // class body... }
1 | Indicate that the dev and integration profiles should be active.
|
2 | Indicate that the dev and integration profiles should be active. |
|
|
有关示例和详细信息,请参阅 Context Configuration with Environment Profiles、@Nested
test class configuration和 `@ActiveProfiles`javadoc中的 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/ActiveProfiles.html。
See Context Configuration with Environment Profiles,
@Nested
test class configuration, and the
@ActiveProfiles
javadoc for
examples and further details.