@Override
public void afterAll(ExtensionContext context) throws Exception {
resetHangTimeout();
+ runAfterAllCallbacks(context);
try {
if (!isNativeOrIntegrationTest(context.getRequiredTestClass()) && (runningQuarkusApplication != null)) {
popMockContext();
@@ -1117,6 +1130,31 @@ public void afterAll(ExtensionContext context) throws Exception {
}
} finally {
currentTestClassStack.pop();
+ outerInstance = null;
+ }
+ }
+
+ private void runAfterAllCallbacks(ExtensionContext context) throws Exception {
+ if (isNativeOrIntegrationTest(context.getRequiredTestClass())) {
+ return;
+ }
+ if (afterAllCallbacks.isEmpty()) {
+ return;
+ }
+
+ Class> quarkusTestContextClass = Class.forName(QuarkusTestContext.class.getName(), true,
+ runningQuarkusApplication.getClassLoader());
+ Object quarkusTestContextInstance = quarkusTestContextClass.getConstructor(Object.class, Object.class)
+ .newInstance(actualTestInstance, outerInstance);
+
+ ClassLoader original = setCCL(runningQuarkusApplication.getClassLoader());
+ try {
+ for (Object afterAllCallback : afterAllCallbacks) {
+ afterAllCallback.getClass().getMethod("afterAll", quarkusTestContextClass)
+ .invoke(afterAllCallback, quarkusTestContextInstance);
+ }
+ } finally {
+ setCCL(original);
}
}
diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestAfterAllCallback.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestAfterAllCallback.java
new file mode 100644
index 0000000000000..867ac995c839c
--- /dev/null
+++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestAfterAllCallback.java
@@ -0,0 +1,11 @@
+package io.quarkus.test.junit.callback;
+
+/**
+ * Can be implemented by classes that shall be called after all test methods in a {@code @QuarkusTest} have been run.
+ *
+ * The implementing class has to be {@linkplain java.util.ServiceLoader deployed as service provider on the class path}.
+ */
+public interface QuarkusTestAfterAllCallback {
+
+ void afterAll(QuarkusTestContext context);
+}
diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestContext.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestContext.java
new file mode 100644
index 0000000000000..8bcb72b69a3fa
--- /dev/null
+++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestContext.java
@@ -0,0 +1,23 @@
+package io.quarkus.test.junit.callback;
+
+/**
+ * Context object passed to {@link QuarkusTestAfterAllCallback}
+ */
+public class QuarkusTestContext {
+
+ private final Object testInstance;
+ private final Object outerInstance;
+
+ public QuarkusTestContext(Object testInstance, Object outerInstance) {
+ this.testInstance = testInstance;
+ this.outerInstance = outerInstance;
+ }
+
+ public Object getTestInstance() {
+ return testInstance;
+ }
+
+ public Object getOuterInstance() {
+ return outerInstance;
+ }
+}
diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestMethodContext.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestMethodContext.java
index 98f8a5ff92389..6062cf8ae4982 100644
--- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestMethodContext.java
+++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/callback/QuarkusTestMethodContext.java
@@ -5,20 +5,15 @@
/**
* Context object passed to {@link QuarkusTestBeforeEachCallback} and {@link QuarkusTestAfterEachCallback}
*/
-public final class QuarkusTestMethodContext {
+public final class QuarkusTestMethodContext extends QuarkusTestContext {
- private final Object testInstance;
private final Method testMethod;
- public QuarkusTestMethodContext(Object testInstance, Method testMethod) {
- this.testInstance = testInstance;
+ public QuarkusTestMethodContext(Object testInstance, Object outerInstance, Method testMethod) {
+ super(testInstance, outerInstance);
this.testMethod = testMethod;
}
- public Object getTestInstance() {
- return testInstance;
- }
-
public Method getTestMethod() {
return testMethod;
}