Skip to content

Commit 57ca8f5

Browse files
committed
Document TestContext bootstrapping in the reference manual
Issue: SPR-11683
1 parent 7c96059 commit 57ca8f5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/asciidoc/testing.adoc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ you can use in your unit and integration tests in conjunction with the TestConte
331331
framework. Refer to the corresponding javadocs for further information, including
332332
default attribute values, attribute aliases, and so on.
333333

334+
===== @BootstrapWith
335+
`@BootstrapWith` is a class-level annotation that is used to configure how the _Spring
336+
TestContext Framework_ is bootstrapped. Specifically, `@BootstrapWith` is used to specify
337+
a custom `TestContextBootstrapper`. Consult the <<testcontext-bootstrapping,Bootstrapping
338+
the TestContext framework>> section for further details.
339+
334340
===== @ContextConfiguration
335341
`@ContextConfiguration` defines class-level metadata that is used to determine how to
336342
load and configure an `ApplicationContext` for integration tests. Specifically,
@@ -980,6 +986,7 @@ annotations_ and reduce configuration duplication across a test suite.
980986
Each of the following may be used as meta-annotations in conjunction with the
981987
<<testcontext-framework,TestContext framework>>.
982988

989+
* `@BootstrapWith`
983990
* `@ContextConfiguration`
984991
* `@ContextHierarchy`
985992
* `@ActiveProfiles`
@@ -1153,6 +1160,30 @@ locations__.
11531160
* `GenericPropertiesContextLoader`: loads a standard `ApplicationContext` from Java
11541161
Properties files.
11551162

1163+
[[testcontext-bootstrapping]]
1164+
==== Bootstrapping the TestContext framework
1165+
1166+
The default configuration for the internals of the Spring TestContext Framework is
1167+
sufficient for all common use cases. However, there are times when a development team or
1168+
third party framework would like to change the default `ContextLoader`, implement a
1169+
custom `TestContext` or `ContextCache`, augment the default sets of
1170+
`ContextCustomizerFactory` and `TestExecutionListener` implementations, etc. For such low
1171+
level control over how the TestContext framework operates, Spring provides a
1172+
bootstrapping strategy.
1173+
1174+
`TestContextBootstrapper` defines the SPI for _bootstrapping_ the TestContext framework.
1175+
A `TestContextBootstrapper` is used by the `TestContextManager` to load the
1176+
`TestExecutionListener` implementations for the current test and to build the
1177+
`TestContext` that it manages. A custom bootstrapping strategy can be configured for a
1178+
test class (or test class hierarchy) via `@BootstrapWith`, either directly or as a
1179+
meta-annotation. If a bootstrapper is not explicitly configured via `@BootstrapWith`,
1180+
either the `DefaultTestContextBootstrapper` or the `WebTestContextBootstrapper` will be
1181+
used, depending on the presence of `@WebAppConfiguration`.
1182+
1183+
Since the `TestContextBootstrapper` SPI is likely to change in the future in order to
1184+
accommodate new requirements, implementers are strongly encouraged not to implement this
1185+
interface directly but rather to extend `AbstractTestContextBootstrapper` or one of its
1186+
concrete subclasses instead.
11561187

11571188
[[testcontext-tel-config]]
11581189
==== TestExecutionListener configuration

0 commit comments

Comments
 (0)