对于最新的稳定版本,请使用 Spring Framework 6.2.0! |
对测试的提前支持
本章介绍了 Spring 对使用 Spring TestContext 框架。
testing 支持扩展了 Spring 的核心 AOT 支持,其中包含 以下功能。
-
当前项目中所有使用 TestContext 框架加载
ApplicationContext
.-
为基于 JUnit Jupiter 和 JUnit 4 的测试类提供显式支持 作为对 TestNG 和其他使用 Spring 核心的测试框架的隐式支持 testing 注解 — 只要测试是使用 JUnit Platform 运行的
TestEngine
,该 ID 已为当前项目注册。
-
-
构建时 AOT 处理:每个测试都是唯一的
ApplicationContext
在当前项目中 将刷新以进行 AOT 处理。 -
运行时 AOT 支持:在 AOT 运行时模式下执行时,Spring 集成测试将 使用 AOT 优化
ApplicationContext
以透明方式参与上下文缓存。
这 |
要提供特定于测试的运行时提示以在 GraalVM 原生映像中使用,您需要 以下选项。
-
实现自定义
TestRuntimeHintsRegistrar
并通过以下方式全局注册META-INF/spring/aot.factories
. -
实现自定义
RuntimeHintsRegistrar
并通过以下方式全局注册META-INF/spring/aot.factories
或本地测试类 通过@ImportRuntimeHints
. -
有关 Spring 的核心运行时提示的详细信息,请参见运行时提示 和注释支持。
这 |
如果您实现自定义ContextLoader
,它必须实现AotContextLoader
在
order 提供 AOT 构建时处理和 AOT 运行时执行支持。注意
但是,Spring Framework 和
Spring Boot 已经实现了AotContextLoader
.
如果您实现自定义TestExecutionListener
,它必须实现AotTestExecutionListener
以便参与 AOT 处理。请参阅SqlScriptsTestExecutionListener
在
这spring-test
module 为例。