Open-Source Wikis

/

Spring Framework

/

Modules

/

spring-core-test

spring-projects/spring-framework

spring-core-test

Active contributors: Sam Brannen, Stéphane Nicoll

Purpose

spring-core-test is internal test infrastructure. It supplies utilities that other Spring modules use in their own tests but that are not appropriate to publish as a general-purpose API. Most prominently, it provides CompileWithForkedClassLoaderExtension for testing AOT-generated code in isolation.

Directory layout

spring-core-test/
└── src/main/java/org/springframework/aot/test/
    ├── agent/                                      # Java agent for test instrumentation
    └── generate/
        ├── compile/                                # JavaCompiler-based test compilation
        └── …

Key abstractions

Type Role
CompileWithForkedClassLoaderExtension JUnit 5 extension that runs each test method in a forked classloader so AOT-generated classes don't bleed between tests
TestCompiler Driver around the JDK JavaCompiler API for in-memory compilation

How it works

The AOT system generates Java source code at build time. To test that code, you need to compile and load it without polluting the main test classloader. spring-core-test solves this by:

  1. Spinning up a fresh URLClassLoader per test method.
  2. Compiling the AOT-generated source against that classloader.
  3. Loading and running the compiled bytecode in isolation.

This is essential for the framework's own AOT testing but not relevant to application code.

Integration points

  • Depends on spring-core.
  • Used by other Spring modules' test code (especially spring-context, spring-beans, spring-web).
  • Not published as a normal dependency — it's testFixtures-flavored.

Entry points for modification

  • New AOT testing utility — Add it here rather than in spring-test. The boundary is "framework-internal testing aid" vs. "application-facing test API."

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

spring-core-test – Spring Framework wiki | Factory