@ContextCustomizerFactories

@ContextCustomizerFactories 是一种注释,可以应用于测试类以注册用于特定测试类、其子类及其嵌套类的 ContextCustomizerFactory 实现。如果您希望全局注册工厂,您应该通过ContextCustomizerFactory Configuration 中描述的自动发现机制进行注册。

以下示例演示如何注册两个 ContextCustomizerFactory 实现:

Java
@ContextConfiguration
@ContextCustomizerFactories({CustomContextCustomizerFactory.class, AnotherContextCustomizerFactory.class}) (1)
class CustomContextCustomizerFactoryTests {
	// class body...
}
1 Register two ContextCustomizerFactory implementations.
Kotlin
@ContextConfiguration
@ContextCustomizerFactories([CustomContextCustomizerFactory::class, AnotherContextCustomizerFactory::class]) (1)
class CustomContextCustomizerFactoryTests {
	// class body...
}
2 Register two ContextCustomizerFactory implementations.

默认情况下,@ContextCustomizerFactories 提供从超类或封闭类继承工厂的支持。有关示例和进一步的详细信息,请参见 @Nested test class configuration 和https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/context/ContextCustomizerFactories.html[@ContextCustomizerFactories] javadoc。