@ActiveProfiles
@ActiveProfiles
是一個註解,可以應用於測試類別,以宣告在為整合測試載入 ApplicationContext 時,應啟用哪些 Bean 定義 Profile。
以下範例指示應啟用 dev
Profile
-
Java
-
Kotlin
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
1 | 指示應啟用 dev Profile。 |
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
1 | 指示應啟用 dev Profile。 |
以下範例指示應同時啟用 dev
和 integration
Profile
-
Java
-
Kotlin
@ContextConfiguration
@ActiveProfiles({"dev", "integration"}) (1)
class DeveloperIntegrationTests {
// class body...
}
1 | 指示應啟用 dev 和 integration Profile。 |
@ContextConfiguration
@ActiveProfiles(["dev", "integration"]) (1)
class DeveloperIntegrationTests {
// class body...
}
1 | 指示應啟用 dev 和 integration Profile。 |
@ActiveProfiles 預設支援繼承由父類別和封閉類別宣告的活動 Bean 定義 Profile。您也可以透過實作自訂的 ActiveProfilesResolver 並使用 @ActiveProfiles 的 resolver 屬性註冊它,以程式化方式解析活動 Bean 定義 Profile。 |
請參閱 環境 Profile 的上下文組態、@Nested
測試類別組態 和 @ActiveProfiles
javadoc 以取得範例和更多詳細資訊。