此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Framework 6.2.10spring-doc.cadn.net.cn

引导 TestContext 框架

Spring TestContext 框架内部的默认配置是对于所有常见用例来说已经足够了。但是,有时开发团队或第三方框架想要更改默认值ContextLoader,实现一个 习惯TestContextContextCache,扩充默认的ContextCustomizerFactoryTestExecutionListener实现,依此类推。 为 对 TestContext 框架如何运行的低级控制,Spring 提供了一个引导策略。spring-doc.cadn.net.cn

TestContextBootstrapper定义用于引导 TestContext 框架的 SPI。 一个TestContextBootstrapperTestContextManager加载TestExecutionListener实现,并构建TestContext它管理的。您可以为test 类(或测试类层次结构)配置自定义引导策略,方法是使用@BootstrapWith,直接或作为meta 注释。如果未使用@BootstrapWith,要么DefaultTestContextBootstrapperWebTestContextBootstrapper使用,具体取决于@WebAppConfiguration.spring-doc.cadn.net.cn

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