From bc7f63b155b36537ca92a6faff3e1bf3d018bae8 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 10 Jan 2024 16:01:47 +0200 Subject: [PATCH] Reset junit test's extension failed state for each test class Fix Quarkus TestExtensions to avoid mistakenly transferring the failed state of one test class to the other. Closes https://github.com/quarkusio/quarkus/issues/37809 --- .../test/junit/QuarkusIntegrationTestExtension.java | 8 +++++++- .../io/quarkus/test/junit/QuarkusTestExtension.java | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java index 6192437575331..ae83728df626c 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java @@ -146,8 +146,14 @@ private QuarkusTestExtensionState ensureStarted(ExtensionContext extensionContex QuarkusTestExtensionState state = getState(extensionContext); Class selectedProfile = findProfile(testClass); boolean wrongProfile = !Objects.equals(selectedProfile, quarkusTestProfile); + // we reset the failed state if we changed test class + boolean isNewTestClass = !Objects.equals(extensionContext.getRequiredTestClass(), currentJUnitTestClass); + if (isNewTestClass && state != null) { + state.setTestFailed(null); + currentJUnitTestClass = extensionContext.getRequiredTestClass(); + } // we reload the test resources if we changed test class and if we had or will have per-test test resources - boolean reloadTestResources = !Objects.equals(extensionContext.getRequiredTestClass(), currentJUnitTestClass) + boolean reloadTestResources = isNewTestClass && (hasPerTestResources || QuarkusTestExtension.hasPerTestResources(extensionContext)); if ((state == null && !failedBoot) || wrongProfile || reloadTestResources) { if (wrongProfile || reloadTestResources) { 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 4002b9139cf36..fdb41b5c4effa 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 @@ -586,10 +586,15 @@ private QuarkusTestExtensionState ensureStarted(ExtensionContext extensionContex QuarkusTestExtensionState state = getState(extensionContext); Class selectedProfile = getQuarkusTestProfile(extensionContext); boolean wrongProfile = !Objects.equals(selectedProfile, quarkusTestProfile); + // we reset the failed state if we changed test class and the new test class is not a nested class + boolean isNewTestClass = !Objects.equals(extensionContext.getRequiredTestClass(), currentJUnitTestClass) + && !isNested(currentJUnitTestClass, extensionContext.getRequiredTestClass()); + if (isNewTestClass && state != null) { + state.setTestFailed(null); + currentJUnitTestClass = extensionContext.getRequiredTestClass(); + } // we reload the test resources if we changed test class and the new test class is not a nested class, and if we had or will have per-test test resources - boolean reloadTestResources = !Objects.equals(extensionContext.getRequiredTestClass(), currentJUnitTestClass) - && !isNested(currentJUnitTestClass, extensionContext.getRequiredTestClass()) - && (hasPerTestResources || hasPerTestResources(extensionContext)); + boolean reloadTestResources = isNewTestClass && (hasPerTestResources || hasPerTestResources(extensionContext)); if ((state == null && !failedBoot) || wrongProfile || reloadTestResources) { if (wrongProfile || reloadTestResources) { if (state != null) {