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
This commit is contained in:
Sam Brannen 2016-09-05 13:39:21 +02:00
parent fbfad8695e
commit e822e4cbe8
1 changed files with 7 additions and 2 deletions

View File

@ -103,8 +103,13 @@ public class DefaultTestContext implements TestContext {
if (context instanceof ConfigurableApplicationContext) { if (context instanceof ConfigurableApplicationContext) {
@SuppressWarnings("resource") @SuppressWarnings("resource")
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context; ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
Assert.state(cac.isActive(), () -> "The ApplicationContext loaded for [" + mergedContextConfiguration Assert.state(cac.isActive(), () ->
+ "] is not active. Ensure that the context has not been closed programmatically."); "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; return context;
} }