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
master
Sam Brannen 8 years ago
parent fbfad8695e
commit e822e4cbe8
  1. 9
      spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java

@ -103,8 +103,13 @@ public class DefaultTestContext implements TestContext {
if (context instanceof ConfigurableApplicationContext) {
@SuppressWarnings("resource")
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
Assert.state(cac.isActive(), () -> "The ApplicationContext loaded for [" + mergedContextConfiguration
+ "] is not active. Ensure that the context has not been closed programmatically.");
Assert.state(cac.isActive(), () ->
"The ApplicationContext loaded for [" + mergedContextConfiguration +
"] is not active. This may be due to one of the following reasons: " +
"1) the context was closed programmatically by user code; " +
"2) the context was closed during parallel test execution either " +
"according to @DirtiesContext semantics or due to automatic eviction " +
"from the ContextCache due to a maximum cache size policy.");
}
return context;
}

Loading…
Cancel
Save