跳到主要内容
版本:7.0.3

启动TestContext框架

Hunyuan 7b 中英对照 Bootstrapping the TestContext Framework

Spring TestContext框架的默认配置对于所有常见的用例来说已经足够了。然而,有时开发团队或第三方框架可能希望更改默认的ContextLoader,实现自定义的TestContextContextCache,扩展默认的ContextCustomizerFactoryTestExecutionListener实现等。为了对TestContext框架的运行方式进行这种低级别的控制,Spring提供了一种启动策略(bootstrapping strategy)。

TestContextBootstrapper 定义了用于启动 TestContext 框架的 SPI(Service Provider Interface)。TestContextManager 会使用 TestContextBootstrapper 来加载当前测试所需的 TestExecutionListener 实现,并构建其所管理的 TestContext。你可以通过使用 @BootstrapWith 注解(可以直接使用,也可以作为元注释)来为某个测试类(或测试类层次结构)配置自定义的启动策略。如果未通过 @BootstrapWith 显式配置启动器,则会根据是否存在 @WebAppConfiguration 注解,使用 DefaultTestContextBootstrapperWebTestContextBootstrapper 之一。

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