Skip to content

Commit e822e4c

Browse files
committed
Improve exception msg for inactive test ApplicationContext
This commit improves the exception message thrown when a test's ApplicationContext is no longer active by explaining that the cause may be due to parallel test execution. Issue: SPR-5863
1 parent fbfad86 commit e822e4c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ public ApplicationContext getApplicationContext() {
103103
if (context instanceof ConfigurableApplicationContext) {
104104
@SuppressWarnings("resource")
105105
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
106-
Assert.state(cac.isActive(), () -> "The ApplicationContext loaded for [" + mergedContextConfiguration
107-
+ "] is not active. Ensure that the context has not been closed programmatically.");
106+
Assert.state(cac.isActive(), () ->
107+
"The ApplicationContext loaded for [" + mergedContextConfiguration +
108+
"] is not active. This may be due to one of the following reasons: " +
109+
"1) the context was closed programmatically by user code; " +
110+
"2) the context was closed during parallel test execution either " +
111+
"according to @DirtiesContext semantics or due to automatic eviction " +
112+
"from the ContextCache due to a maximum cache size policy.");
108113
}
109114
return context;
110115
}

0 commit comments

Comments
 (0)