SpringBootDependencyInjectionTestExecutionListener tries to do this today but it doesn't work as calling testContext.getApplicationContext() after the failure results in a second attempt to create the context which also fails. #24888 hopes to fix this in 2.x. In 3.0, we can use a new SPI that's been proposed in the test context framework to process the failure.
Comment From: sbrannen
This issue is no longer blocked since https://github.com/spring-projects/spring-framework/issues/28826 has been pushed to main for inclusion in Spring Framework 6.0 RC2.
As stated in the Javadoc for SmartContextLoader.loadContext(MergedContextConfiguration), the SpringBootContextLoader will need to be updated with a try-catch block in order to throw the newly introduced org.springframework.test.context.ContextLoadException.
In addition, SpringBootTestContextBootstrapper will need to override the newly introduced getApplicationContextFailureProcessor() method to return an ApplicationContextFailureProcessor that replaces the logic currently in SpringBootDependencyInjectionTestExecutionListener.outputConditionEvaluationReport(...).
Comment From: wilkinsona
While DefaultTestExecutionListenersPostProcessor remains in a deprecated form, I think that SpringBootTestContextBootstrapper should continue to discover them via spring.factories and call them.
Comment From: sbrannen
Since this and #32995 effectively fix #24888 (which is a bug), I'm wondering if it wouldn't be better to use a label other than task so that the fix shows up in the automatically generated change log.