Loading...
Spring Framework Reference Documentation 7.0.2의 Ahead of Time Support for Tests의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
This chapter covers Spring’s Ahead of Time (AOT) support for integration tests using the Spring TestContext Framework.
The testing support extends Spring’s core AOT support with the following features.
ApplicationContext.
TestEngine that is registered for the current project.ApplicationContext in the current project
will be refreshed for AOT processing.ApplicationContext that participates transparently with the
context cache.All tests are enabled in AOT mode by default. However, you can selectively disable an
entire test class or individual test method in AOT mode by annotating it with
@DisabledInAotMode.
When using JUnit Jupiter, you may selectively enable or disable tests in a GraalVM native
image via Jupiter’s @EnabledInNativeImage and @DisabledInNativeImage annotations.
Note that @DisabledInAotMode also disables the annotated test class or test method when
running within a GraalVM native image, analogous to JUnit Jupiter’s
@DisabledInNativeImage annotation.
기본적으로 빌드 타임 AOT 처리 중에 오류가 발생하면 예외가 던져지고 전체 프로세스가 즉시 실패합니다. 오류가 발생한 이후에도 빌드 타임 AOT 처리가 계속되기를 원한다면,
failOnError모드를 비활성화할 수 있으며, 이 경우 오류는WARN레벨로 로깅되거나DEBUG레벨에서 더 상세하게 로깅됩니다.failOnError모드는 JVM 시스템 프로퍼티인spring.test.aot.processing.failOnError를false로 설정하여 커맨드 라인이나 빌드 스크립트에서 비활성화할 수 있습니다. 대안으로, 동일한 프로퍼티를SpringProperties메커니즘을 통해 설정할 수 있습니다.
JPA의
@PersistenceContext와@PersistenceUnit어노테이션은 AOT 모드에서 테스트 클래스 내에서 의존성 주입을 수행하는 데 사용할 수 없습니다. 그러나 Spring Framework 7.0부터는EntityManager또는EntityManagerFactory를 테스트에 주입할 때 각각@PersistenceContext와@PersistenceUnit대신@Autowired를 사용할 수 있습니다.
@ContextHierarchy어노테이션은 AOT 모드에서 지원되지 않습니다.
To provide test-specific runtime hints for use within a GraalVM native image, you have the following options.
TestRuntimeHintsRegistrar
and register it globally via META-INF/spring/aot.factories.RuntimeHintsRegistrar
and register it globally via META-INF/spring/aot.factories or locally on a test class
via @ImportRuntimeHints.@Reflective or
@RegisterReflectionForBinding.
TestRuntimeHintsRegistrarAPI는 코어RuntimeHintsRegistrarAPI의 컴패니언 역할을 합니다. 특정 테스트 클래스에 특화되지 않은 테스트 지원을 위한 글로벌 힌트를 등록해야 한다면, 테스트 전용 API보다RuntimeHintsRegistrar구현을 선호해야 합니다.
If you implement a custom ContextLoader, it must implement
AotContextLoader in
order to provide AOT 빌드 타임 처리 and AOT 런타임 실행 지원.
Note,
however, that all context loader implementations provided by the Spring Framework and
Spring Boot already implement AotContextLoader.
If you implement a custom TestExecutionListener, it must implement
AotTestExecutionListener
in order to participate in AOT processing. See the SqlScriptsTestExecutionListener in
the spring-test module for an example.
TestContext Framework Support Classes
WebTestClient