Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid loading of test ApplicationContext in AOT mode if AOT processi…
…ng failed Prior to this commit, if AOT processing of a test's ApplicationContext failed, the TestContext Framework (TCF) still attempted to load the context via standard (JVM) mechanisms when running in AOT mode. For example, if a test class uses Spring Boot's @MockBean, AOT processing of that test's context will fail with a WARN log message, and there will no mapping from that test class to an AOT-generated ApplicationContextInitializer (ACI). Consequently, when the test suite is run in AOT mode that particular test class will currently fail with a confusing stack trace due to the fact that Spring Boot's SpringApplication attempts to locate a "main" ACI instead of the missing "test" ACI (missing because it was not generated during AOT processing). In general, the TCF should not attempt to load an ApplicationContext in "JVM mode" while running in "AOT mode". This commit therefore reworks the logic in DefaultCacheAwareContextLoaderDelegate to fail fast (with a meaningful error message) if an AOT-generated ACI cannot be found while running in AOT mode. This avoids the aforementioned confusion when @MockBean tests fail in AOT mode (on the JVM or within a native image), and it also helps to diagnose build problems if AOT processing has not yet been performed for the project's test suite. Closes gh-29579
- Loading branch information