@@ -6982,6 +6982,65 @@ classes by using `@ContextConfiguration`, `@TestExecutionListeners`, and so on a
69826982manually instrumenting your test class with a `TestContextManager`. See the source code
69836983of `AbstractTestNGSpringContextTests` for an example of how to instrument your test class.
69846984
6985+ [[testcontext-aot]]
6986+ ==== Ahead of Time Support for Tests
6987+
6988+ This chapter covers Spring's Ahead of Time (AOT) support for integration tests using the
6989+ Spring TestContext Framework.
6990+
6991+ The testing support extends Spring's <<core.adoc#aot,core AOT support>> with the
6992+ following features.
6993+
6994+ * Build-time detection of all integration tests in the current project that use the
6995+ TestContext framework to load an `ApplicationContext`.
6996+ - Provides explicit support for test classes based on JUnit Jupiter and JUnit 4 as well
6997+ as implicit support for TestNG and other testing frameworks that use Spring's core
6998+ testing annotations -- as long as the tests are run using a JUnit Platform
6999+ `TestEngine` that is registered for the current project.
7000+ * Build-time AOT processing: each unique test `ApplicationContext` in the current project
7001+ will be <<core.adoc#aot-refresh,refreshed for AOT processing>>.
7002+ * Runtime AOT support: when executing in AOT runtime mode, a Spring integration test will
7003+ use an AOT-optimized `ApplicationContext` that participates transparently with the
7004+ <<testcontext-ctx-management-caching, context cache>>.
7005+
7006+ [WARNING]
7007+ ====
7008+ The `@ContextHierarchy` annotation is currently not supported in AOT mode.
7009+ ====
7010+
7011+ To provide test-specific runtime hints for use within a GraalVM native image, you have
7012+ the following options.
7013+
7014+ * Implement a custom
7015+ {api-spring-framework}/test/context/aot/TestRuntimeHintsRegistrar.html[`TestRuntimeHintsRegistrar`]
7016+ and register it globally via `META-INF/spring/aot.factories`.
7017+ * Implement a custom {api-spring-framework}/aot/hint/RuntimeHintsRegistrar.html[`RuntimeHintsRegistrar`]
7018+ and register it globally via `META-INF/spring/aot.factories` or locally on a test class
7019+ via {api-spring-framework}/context/annotation/ImportRuntimeHints.html[`@ImportRuntimeHints`].
7020+ * Annotate a test class with {api-spring-framework}/aot/hint/annotation/Reflective.html[`@Reflective`] or
7021+ {api-spring-framework}/aot/hint/annotation/RegisterReflectionForBinding.html[`@RegisterReflectionForBinding`].
7022+ * See <<core.adoc#aot-hints,Runtime Hints>> for details on Spring's core runtime hints
7023+ and annotation support.
7024+
7025+ [TIP]
7026+ ====
7027+ The `TestRuntimeHintsRegistrar` API serves as a companion to the core
7028+ `RuntimeHintsRegistrar` API. If you need to register global hints for testing support
7029+ that are not specific to particular test classes, favor implementing
7030+ `RuntimeHintsRegistrar` over the test-specific API.
7031+ ====
7032+
7033+ If you implement a custom `ContextLoader`, it must implement
7034+ {api-spring-framework}/test/context/aot/AotContextLoader.html[`AotContextLoader`] in
7035+ order to provide AOT build-time processing and AOT runtime execution support. Note,
7036+ however, that all context loader implementations provided by the Spring Framework and
7037+ Spring Boot already implement `AotContextLoader`.
7038+
7039+ If you implement a custom `TestExecutionListener`, it must implement
7040+ {api-spring-framework}/test/context/aot/AotTestExecutionListener.html[`AotTestExecutionListener`]
7041+ in order to participate in AOT processing. See the `SqlScriptsTestExecutionListener` in
7042+ the `spring-test` module for an example.
7043+
69857044
69867045
69877046include::testing/testing-webtestclient.adoc[leveloffset=+2]
0 commit comments