引导TestContext框架

Spring TestContext框架内部的默认配置对于所有常见用例都是足够的。然而,有时开发团队或第三方框架希望更改默认的ContextLoader,实现自定义TestContextContextCache,增加默认的ContextCustomizerFactoryTestExecutionListener实现集等。对于对TestContext框架操作的低级控制,Spring提供了一种引导策略。

TestContextBootstrapper定义了引导TestContext框架的SPI。一个TestContextBootstrapperTestContextManager用于加载当前测试的TestExecutionListener实现,并构建它管理的TestContext。您可以通过直接使用@BootstrapWith或作为元注释来为测试类(或测试类层次结构)配置自定义引导策略。如果没有通过@BootstrapWith显式配置引导程序,则根据是否存在@WebAppConfiguration,将使用DefaultTestContextBootstrapperWebTestContextBootstrapper

由于未来TestContextBootstrapper SPI可能会发生变化(以适应新的需求),我们强烈建议实现者不要直接实现此接口,而是扩展AbstractTestContextBootstrapper或其具体子类之一。