Merge branch '6.2.x'

This commit is contained in:
Sam Brannen
2025-09-25 17:55:22 +02:00
7 changed files with 159 additions and 27 deletions
@@ -73,7 +73,7 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App
private final TestContextManager testContextManager;
private @Nullable Throwable testException;
private final ThreadLocal<@Nullable Throwable> testException = new ThreadLocal<>();
/**
@@ -139,31 +139,33 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App
public void run(IHookCallBack callBack, ITestResult testResult) {
Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod();
boolean beforeCallbacksExecuted = false;
Throwable currentException = null;
try {
this.testContextManager.beforeTestExecution(this, testMethod);
beforeCallbacksExecuted = true;
}
catch (Throwable ex) {
this.testException = ex;
currentException = ex;
}
if (beforeCallbacksExecuted) {
callBack.runTestMethod(testResult);
this.testException = getTestResultException(testResult);
currentException = getTestResultException(testResult);
}
try {
this.testContextManager.afterTestExecution(this, testMethod, this.testException);
this.testContextManager.afterTestExecution(this, testMethod, currentException);
}
catch (Throwable ex) {
if (this.testException == null) {
this.testException = ex;
if (currentException == null) {
currentException = ex;
}
}
if (this.testException != null) {
throwAsUncheckedException(this.testException);
if (currentException != null) {
this.testException.set(currentException);
throwAsUncheckedException(currentException);
}
}
@@ -178,10 +180,10 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App
@AfterMethod(alwaysRun = true)
protected void springTestContextAfterTestMethod(Method testMethod) throws Exception {
try {
this.testContextManager.afterTestMethod(this, testMethod, this.testException);
this.testContextManager.afterTestMethod(this, testMethod, this.testException.get());
}
finally {
this.testException = null;
this.testException.remove();
}
}