引导 TestContext 框架
对于所有常见用例,Spring TestContext 框架内部结构的默认配置已经足够。但是,有时开发团队或第三方框架可能希望更改默认的 ContextLoader
、实现自定义的 TestContext
或 ContextCache
、增强默认的 ContextCustomizerFactory
和 TestExecutionListener
实现集合等。为了对 TestContext 框架的操作方式进行这种低级控制,Spring 提供了引导策略。
TestContextBootstrapper
定义了引导 TestContext 框架的 SPI。TestContextManager
使用 TestContextBootstrapper
来加载当前测试的 TestExecutionListener
实现,并构建它管理的 TestContext
。您可以通过直接或作为元注解使用 @BootstrapWith
为测试类(或测试类层次结构)配置自定义引导策略。如果未使用 @BootstrapWith
明确配置引导程序,则将使用 DefaultTestContextBootstrapper
或 WebTestContextBootstrapper
,具体取决于是否存在 @WebAppConfiguration
。
由于 TestContextBootstrapper
SPI 未来可能会更改(以适应新的需求),我们强烈建议实现者不要直接实现此接口,而是扩展 AbstractTestContextBootstrapper
或其具体子类之一。