[SPR-4702] now updating TestContext state before calling before/after test class life cycle callbacks.
This commit is contained in:
parent
ba425c34f8
commit
2dee54b78a
|
|
@ -47,10 +47,9 @@ import org.springframework.util.Assert;
|
||||||
* execution points:
|
* execution points:
|
||||||
* </p>
|
* </p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #beforeTestClass() before test class execution}:
|
* <li>{@link #beforeTestClass() before test class execution}: prior to any
|
||||||
* prior to any <em>before class methods</em> of a particular testing
|
* <em>before class methods</em> of a particular testing framework (e.g., JUnit
|
||||||
* framework (e.g., JUnit 4's {@link org.junit.BeforeClass
|
* 4's {@link org.junit.BeforeClass @BeforeClass})</li>
|
||||||
* @BeforeClass})</li>
|
|
||||||
* <li>{@link #prepareTestInstance(Object) test instance preparation}:
|
* <li>{@link #prepareTestInstance(Object) test instance preparation}:
|
||||||
* immediately following instantiation of the test instance</li>
|
* immediately following instantiation of the test instance</li>
|
||||||
* <li>{@link #beforeTestMethod(Object,Method) before test method execution}:
|
* <li>{@link #beforeTestMethod(Object,Method) before test method execution}:
|
||||||
|
|
@ -60,9 +59,8 @@ import org.springframework.util.Assert;
|
||||||
* execution}: after any <em>after methods</em> of a particular testing
|
* execution}: after any <em>after methods</em> of a particular testing
|
||||||
* framework (e.g., JUnit 4's {@link org.junit.After @After})</li>
|
* framework (e.g., JUnit 4's {@link org.junit.After @After})</li>
|
||||||
* <li>{@link #afterTestClass() after test class execution}: after any
|
* <li>{@link #afterTestClass() after test class execution}: after any
|
||||||
* <em>after class methods</em> of a particular testing
|
* <em>after class methods</em> of a particular testing framework (e.g., JUnit
|
||||||
* framework (e.g., JUnit 4's {@link org.junit.AfterClass
|
* 4's {@link org.junit.AfterClass @AfterClass})</li>
|
||||||
* @AfterClass})</li>
|
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
|
|
@ -152,6 +150,17 @@ public class TestContextManager {
|
||||||
return Collections.unmodifiableList(this.testExecutionListeners);
|
return Collections.unmodifiableList(this.testExecutionListeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a copy of the {@link TestExecutionListener TestExecutionListeners}
|
||||||
|
* registered for this <code>TestContextManager</code> in reverse order.
|
||||||
|
*/
|
||||||
|
private List<TestExecutionListener> getReversedTestExecutionListeners() {
|
||||||
|
List<TestExecutionListener> listenersReversed = new ArrayList<TestExecutionListener>(
|
||||||
|
getTestExecutionListeners());
|
||||||
|
Collections.reverse(listenersReversed);
|
||||||
|
return listenersReversed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an array of newly instantiated {@link TestExecutionListener
|
* Retrieves an array of newly instantiated {@link TestExecutionListener
|
||||||
* TestExecutionListeners} for the specified {@link Class class}. If
|
* TestExecutionListeners} for the specified {@link Class class}. If
|
||||||
|
|
@ -264,6 +273,7 @@ public class TestContextManager {
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("beforeTestClass(): class [" + testClass + "]");
|
logger.trace("beforeTestClass(): class [" + testClass + "]");
|
||||||
}
|
}
|
||||||
|
getTestContext().updateState(null, null, null);
|
||||||
|
|
||||||
for (TestExecutionListener testExecutionListener : getTestExecutionListeners()) {
|
for (TestExecutionListener testExecutionListener : getTestExecutionListeners()) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -393,14 +403,10 @@ public class TestContextManager {
|
||||||
}
|
}
|
||||||
getTestContext().updateState(testInstance, testMethod, exception);
|
getTestContext().updateState(testInstance, testMethod, exception);
|
||||||
|
|
||||||
|
Exception afterTestMethodException = null;
|
||||||
// Traverse the TestExecutionListeners in reverse order to ensure proper
|
// Traverse the TestExecutionListeners in reverse order to ensure proper
|
||||||
// "wrapper"-style execution of listeners.
|
// "wrapper"-style execution of listeners.
|
||||||
List<TestExecutionListener> listenersReversed = new ArrayList<TestExecutionListener>(
|
for (TestExecutionListener testExecutionListener : getReversedTestExecutionListeners()) {
|
||||||
getTestExecutionListeners());
|
|
||||||
Collections.reverse(listenersReversed);
|
|
||||||
|
|
||||||
Exception afterTestMethodException = null;
|
|
||||||
for (TestExecutionListener testExecutionListener : listenersReversed) {
|
|
||||||
try {
|
try {
|
||||||
testExecutionListener.afterTestMethod(getTestContext());
|
testExecutionListener.afterTestMethod(getTestContext());
|
||||||
}
|
}
|
||||||
|
|
@ -440,15 +446,12 @@ public class TestContextManager {
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("afterTestClass(): class [" + testClass + "]");
|
logger.trace("afterTestClass(): class [" + testClass + "]");
|
||||||
}
|
}
|
||||||
|
getTestContext().updateState(null, null, null);
|
||||||
// Traverse the TestExecutionListeners in reverse order to ensure proper
|
|
||||||
// "wrapper"-style execution of listeners.
|
|
||||||
List<TestExecutionListener> listenersReversed = new ArrayList<TestExecutionListener>(
|
|
||||||
getTestExecutionListeners());
|
|
||||||
Collections.reverse(listenersReversed);
|
|
||||||
|
|
||||||
Exception afterTestClassException = null;
|
Exception afterTestClassException = null;
|
||||||
for (TestExecutionListener testExecutionListener : listenersReversed) {
|
// Traverse the TestExecutionListeners in reverse order to ensure proper
|
||||||
|
// "wrapper"-style execution of listeners.
|
||||||
|
for (TestExecutionListener testExecutionListener : getReversedTestExecutionListeners()) {
|
||||||
try {
|
try {
|
||||||
testExecutionListener.afterTestClass(getTestContext());
|
testExecutionListener.afterTestClass(getTestContext());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue