|
对于最新的稳定版本,请使用 Spring Framework 7.0.6! |
引导TestContext框架
Spring TestContext 框架的内部实现默认配置足以满足所有常见用例场景。然而,开发团队或第三方框架有时可能需要修改默认的 ContextLoader、实现自定义的 TestContext 或 ContextCache、扩展默认的 ContextCustomizerFactory 和 TestExecutionListener 实现集合等。为了实现对 TestContext 框架运行方式的底层控制,Spring 提供了一套引导策略。
TestContextBootstrapper 定义了用于引导 TestContext 框架的 SPI(服务提供接口)。TestContextManager 使用 TestContextBootstrapper 来加载当前测试的 TestExecutionListener 实现,并构建其管理的 TestContext。您可以通过直接使用 @BootstrapWith 或将其作为元注解,为测试类(或测试类层次结构)配置自定义引导策略。若未使用 @BootstrapWith 显式配置引导程序,则将根据 @WebAppConfiguration 的存在情况,选用 DefaultTestContextBootstrapper 或 WebTestContextBootstrapper。
由于未来的 TestContextBootstrapper SPI 可能会发生变化(以适应新的需求),我们强烈建议实现者不要直接实现此接口,而是继承 AbstractTestContextBootstrapper 或其具体子类之一。