From 199b31ee9fbcd095c81d7241e9ed2ffdb2bb4838 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 9 Aug 2021 15:57:20 +1000 Subject: [PATCH] Set correct TCCL for dynamic tests This will be needed for the Cucumber quarkiverse extension --- .../quarkus/test/junit/QuarkusTestExtension.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index 8674b8b29478e..1ecc7379b9946 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -889,6 +889,21 @@ public void interceptTestMethod(Invocation invocation, ReflectiveInvocatio invocation.skip(); } + @Override + public void interceptDynamicTest(Invocation invocation, ExtensionContext extensionContext) throws Throwable { + if (runningQuarkusApplication == null) { + invocation.proceed(); + return; + } + var old = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(runningQuarkusApplication.getClassLoader()); + invocation.proceed(); + } finally { + Thread.currentThread().setContextClassLoader(old); + } + } + @Override public void interceptTestTemplateMethod(Invocation invocation, ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable {