From e822e4cbe87b09b901eb2363bc884a635a96a01e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 5 Sep 2016 13:39:21 +0200 Subject: [PATCH] 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 --- .../test/context/support/DefaultTestContext.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java b/spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java index 5066dce3ef..72da428519 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java +++ b/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; }