Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SPI for processing ApplicationContext failures in the TestContext framework #28826

Closed
sbrannen opened this issue Jul 15, 2022 · 1 comment
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

Overview

When a failure occurs while loading an ApplicationContext in the Spring TestContext Framework, it would be useful to have a first-class SPI for processing the exception.

For example, Spring Boot's testing support currently has a SpringBootDependencyInjectionTestExecutionListener that is responsible for generating a detailed failure report to help diagnose what went wrong; however, Spring Boot has to replace the standard DependencyInjectionTestExecutionListener with the Spring Boot specific one. In addition, the SpringBootDependencyInjectionTestExecutionListener has some drawbacks (see spring-projects/spring-boot#24888).

We should therefor introduce a first-class SPI in the TestContext framework for "processing" ApplicationContext load failures -- basically a new interface that third parties like Spring Boot can implement and register (potentially via the spring.factories mechanism).

Related Issues

@wilkinsona
Copy link
Member

spring-projects/spring-boot#31793 is tracking Boot making use of the new SPI.

@sbrannen sbrannen modified the milestones: 6.0.0-M6, 6.0.0-RC1 Aug 29, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-RC1, 6.0.0-RC2 Oct 11, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Oct 18, 2022
This commit introduces an ApplicationContextFailureProcessor SPI in the
Spring TestContext Framework that allows third parties to process
failures that occur while a SmartContextLoader attempts to load an
ApplicationContext.

SmartContextLoader implementations must introduce a try-catch block
around the loading code and throw a ContextLoadException that wraps
the failed ApplicationContext and the cause of the failure.

Extensions of AbstractTestContextBootstrapper can configure an
ApplicationContextFailureProcessor by overriding the new protected
getApplicationContextFailureProcessor() method.

DefaultCacheAwareContextLoaderDelegate unwraps any ContextLoadException
and delegates to the configured ApplicationContextFailureProcessor for
processing.

Closes spring-projectsgh-28826
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Oct 18, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Oct 26, 2022
At the request of the Spring Boot team, ApplicationContextFailureProcessor
implementations are now loaded via the spring.factories mechanism
instead of supporting a single processor registered via subclasses of
AbstractTestContextBootstrapper.

This makes the retrieval and handling of processors internal to
DefaultCacheAwareContextLoaderDelegate, while simultaneously supporting
multiple processors that can be registered by anyone (i.e., not
limited to projects that implement custom TestContextBootstrappers).

See spring-projectsgh-28826
Closes spring-projectsgh-29387
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants