@ContextHierarchy
@ContextHierarchy は、テストクラスに適用して統合テスト用の ApplicationContext インスタンスの階層を定義できるアノテーションです。@ContextHierarchy は、1 つ以上の @ContextConfiguration インスタンスのリストで宣言する必要があります。各インスタンスはコンテキスト階層のレベルを定義します。次の例は、単一のテストクラス内での @ContextHierarchy の使用を示しています (テストクラス階層内では @ContextHierarchy も使用できます)。
Java
Kotlin
@ContextHierarchy({
@ContextConfiguration("/parent-config.xml"),
@ContextConfiguration("/child-config.xml")
})
class ContextHierarchyTests {
// class body...
}@ContextHierarchy(
ContextConfiguration("/parent-config.xml"),
ContextConfiguration("/child-config.xml"))
class ContextHierarchyTests {
// class body...
}Java
Kotlin
@WebAppConfiguration
@ContextHierarchy({
@ContextConfiguration(classes = AppConfig.class),
@ContextConfiguration(classes = WebConfig.class)
})
class WebIntegrationTests {
// class body...
}@WebAppConfiguration
@ContextHierarchy(
ContextConfiguration(classes = [AppConfig::class]),
ContextConfiguration(classes = [WebConfig::class]))
class WebIntegrationTests {
// class body...
} テストクラス階層内のコンテキスト階層の特定のレベルの構成をマージまたはオーバーライドする必要がある場合は、クラス階層の対応する各レベルで @ContextConfiguration の name 属性に同じ値を指定して、そのレベルに明示的に名前を付ける必要があります。さらなる例については、コンテキストの階層および @ContextHierarchy javadoc を参照してください。