此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Framework 6.2.10! |
引导 TestContext 框架
Spring TestContext 框架内部的默认配置是
足以满足所有常见用例。但是,有时开发团队或
第三方框架想要更改默认值ContextLoader
,实现一个
习惯TestContext
或ContextCache
,扩充默认的ContextCustomizerFactory
和TestExecutionListener
实现,依此类推。为
对 TestContext 框架如何运行的这种低级控制,Spring 提供了一个
引导策略。
TestContextBootstrapper
定义用于引导 TestContext 框架的 SPI。一个TestContextBootstrapper
由TestContextManager
加载TestExecutionListener
实现,并构建TestContext
它管理。您可以为
测试类(或测试类层次结构),使用@BootstrapWith
,直接或作为
元注释。如果未使用@BootstrapWith
,要么DefaultTestContextBootstrapper
或WebTestContextBootstrapper
使用,具体取决于@WebAppConfiguration
.
由于TestContextBootstrapper
SPI 将来可能会发生变化(以适应
new 要求),我们强烈建议实现者不要实现此接口
直接,而是扩展AbstractTestContextBootstrapper
或其混凝土之一
子类。