diff --git a/framework-docs/modules/ROOT/nav.adoc b/framework-docs/modules/ROOT/nav.adoc index c0aa14fcb7..932ab6a0e9 100644 --- a/framework-docs/modules/ROOT/nav.adoc +++ b/framework-docs/modules/ROOT/nav.adoc @@ -130,6 +130,7 @@ **** xref:testing/testcontext-framework/ctx-management/web.adoc[] **** xref:testing/testcontext-framework/ctx-management/web-mocks.adoc[] **** xref:testing/testcontext-framework/ctx-management/caching.adoc[] +**** xref:testing/testcontext-framework/ctx-management/failure-threshold.adoc[] **** xref:testing/testcontext-framework/ctx-management/hierarchies.adoc[] *** xref:testing/testcontext-framework/fixture-di.adoc[] *** xref:testing/testcontext-framework/web-scoped-beans.adoc[] diff --git a/framework-docs/modules/ROOT/pages/appendix.adoc b/framework-docs/modules/ROOT/pages/appendix.adoc index 64e97d84ee..8c9e1b7476 100644 --- a/framework-docs/modules/ROOT/pages/appendix.adoc +++ b/framework-docs/modules/ROOT/pages/appendix.adoc @@ -64,6 +64,11 @@ on a test class. See xref:testing/annotations/integration-junit-jupiter.adoc#int | The maximum size of the context cache in the _Spring TestContext Framework_. See xref:testing/testcontext-framework/ctx-management/caching.adoc[Context Caching]. +| `spring.test.context.failure.threshold` +| The failure threshold for errors encountered while attempting to load an `ApplicationContext` +in the _Spring TestContext Framework_. See +xref:testing/testcontext-framework/ctx-management/failure-threshold.adoc[Context Failure Threshold]. + | `spring.test.enclosing.configuration` | The default _enclosing configuration inheritance mode_ to use if `@NestedTestConfiguration` is not present on a test class. See diff --git a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management.adoc b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management.adoc index 30ce7bd59d..61fe27babe 100644 --- a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management.adoc +++ b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management.adoc @@ -119,5 +119,6 @@ advanced use cases. * xref:testing/testcontext-framework/ctx-management/dynamic-property-sources.adoc[Context Configuration with Dynamic Property Sources] * xref:testing/testcontext-framework/ctx-management/web.adoc[Loading a `WebApplicationContext`] * xref:testing/testcontext-framework/ctx-management/caching.adoc[Context Caching] +* xref:testing/testcontext-framework/ctx-management/failure-threshold.adoc[Context Failure Threshold] * xref:testing/testcontext-framework/ctx-management/hierarchies.adoc[Context Hierarchies] diff --git a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management/failure-threshold.adoc b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management/failure-threshold.adoc new file mode 100644 index 0000000000..b4cda24501 --- /dev/null +++ b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/ctx-management/failure-threshold.adoc @@ -0,0 +1,23 @@ +[[testcontext-ctx-management-failure-threshold]] += Context Failure Threshold + +As of Spring Framework 6.1, a context _failure threshold_ policy is in place which helps +avoid repeated attempts to load a failing `ApplicationContext`. By default, the failure +threshold is set to `1` which means that only one attempt will be made to load an +`ApplicationContext` for a given context cache key (see +xref:testing/testcontext-framework/ctx-management/caching.adoc[Context Caching]). Any +subsequent attempt to load the `ApplicationContext` for the same context cache key will +result in an immediate `IllegalStateException` with an error message which explains that +the attempt was preemptively skipped. This behavior allows individual test classes and +test suites to fail faster by avoiding repeated attempts to load an `ApplicationContext` +that will never successfully load -- for example, due to a configuration error or a missing +external resource that prevents the context from loading in the current environment. + +You can configure the context failure threshold from the command line or a build script +by setting a JVM system property named `spring.test.context.failure.threshold` with a +positive integer value. As an alternative, you can set the same property via the +xref:appendix.adoc#appendix-spring-properties[`SpringProperties`] mechanism. + +NOTE: If you wish to effectively disable the context failure threshold, you can set the +property to a very large value. For example, from the command line you could set the +system property via `-Dspring.test.context.failure.threshold=1000000`.