测试 GraalVM 原生镜像
原文:https://docs.spring.io/spring-boot/how-to/native-image/testing-native-applications.html (Spring Boot 4.2.0)
使用 JVM 测试 AOT 处理
可以在 JVM 上测试 AOT 处理,而无需构建完整的原生镜像。使用 -Dspring.aot.enabled=true 运行应用或测试,这会执行 AOT 优化后的代码:
$ java -Dspring.aot.enabled=true -jar myapplication.jar
这比构建原生镜像快得多,适合在开发周期中快速验证 AOT 兼容性。
使用 Native Build Tools 测试
可以使用 Native Build Tools 插件运行原生镜像测试。
使用 Maven
native-maven-plugin 提供 native-test 目标,会在原生镜像中收集并运行测试:
$ mvn -Pnative native:test
使用 Gradle
GraalVM Native Build Tools 插件提供 nativeTest 任务:
$ gradle nativeTest
原生测试需要将 JUnit 平台配置为在原生镜像中运行,通常需要添加 junit-platform-native 依赖并配置提示。