Bootstrapping the TestContext Framework
Spring TestContext Framework 内部默认配置足以满足所有常见用例。但是,有时开发团队或第三方框架需要更改默认 “ContextLoader”,实现自定义 “TestContext” 或 “ContextCache”,扩充默认的 “ContextCustomizerFactory” 和 “TestExecutionListener” 实现集等等。为了像这样深入控制 TestContext 框架的操作,Spring 提供了一种引导策略。
The default configuration for the internals of the Spring TestContext Framework is
sufficient for all common use cases. However, there are times when a development team or
third party framework would like to change the default ContextLoader
, implement a
custom TestContext
or ContextCache
, augment the default sets of
ContextCustomizerFactory
and TestExecutionListener
implementations, and so on. For
such low-level control over how the TestContext framework operates, Spring provides a
bootstrapping strategy.
“TestContextBootstrapper” 定义了用于引导 TestContext 框架的 SPI。“TestContextManager” 使用 “TestContextBootstrapper” 为当前测试加载 “TestExecutionListener” 实现,并构建其管理的 “TestContext”。你可以使用 “@BootstrapWith” 为测试类(或测试类层次结构)配置自定义引导策略,直接使用或作为元注释。如果没有使用 “@BootstrapWith” 显式配置引导程序,则根据是否存在 “@WebAppConfiguration” 使用 “DefaultTestContextBootstrapper” 或 “WebTestContextBootstrapper”。
TestContextBootstrapper
defines the SPI for bootstrapping the TestContext framework. A
TestContextBootstrapper
is used by the TestContextManager
to load the
TestExecutionListener
implementations for the current test and to build the
TestContext
that it manages. You can configure a custom bootstrapping strategy for a
test class (or test class hierarchy) by using @BootstrapWith
, either directly or as a
meta-annotation. If a bootstrapper is not explicitly configured by using
@BootstrapWith
, either the DefaultTestContextBootstrapper
or the
WebTestContextBootstrapper
is used, depending on the presence of @WebAppConfiguration
.
由于 TestContextBootstrapper SPI 未来可能会发生变化(以满足新要求),我们强烈建议实现者不要直接实现此接口,而是扩展 “AbstractTestContextBootstrapper” 或其其中一个具体子类。
Since the TestContextBootstrapper
SPI is likely to change in the future (to accommodate
new requirements), we strongly encourage implementers not to implement this interface
directly but rather to extend AbstractTestContextBootstrapper
or one of its concrete
subclasses instead.