diff --git a/allure-junit-platform/src/main/java/io/qameta/allure/junitplatform/AllureJunitPlatform.java b/allure-junit-platform/src/main/java/io/qameta/allure/junitplatform/AllureJunitPlatform.java index 1550ab0a6..a05b046d6 100644 --- a/allure-junit-platform/src/main/java/io/qameta/allure/junitplatform/AllureJunitPlatform.java +++ b/allure-junit-platform/src/main/java/io/qameta/allure/junitplatform/AllureJunitPlatform.java @@ -141,6 +141,8 @@ public class AllureJunitPlatform implements TestExecutionListener { private static final boolean HAS_CUCUMBERJVM7_IN_CLASSPATH = isClassAvailableOnClasspath("io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"); + private static final boolean HAS_CUCUMBERJVM8_IN_CLASSPATH = isClassAvailableOnClasspath("io.qameta.allure.cucumber8jvm.AllureCucumber8Jvm"); + private static final boolean HAS_KARATE_IN_CLASSPATH = isClassAvailableOnClasspath("io.qameta.allure.karate.AllureKarate"); private static final String ENGINE_SPOCK2 = "spock"; @@ -228,10 +230,21 @@ private boolean shouldSkipReportingFor(final TestIdentifier testIdentifier) { final String engine = maybeEngine.get(); return HAS_SPOCK2_IN_CLASSPATH && ENGINE_SPOCK2.equals(engine) - || HAS_CUCUMBERJVM7_IN_CLASSPATH && ENGINE_CUCUMBER.equals(engine) + || shouldSkipCucumberEngine(engine) || HAS_KARATE_IN_CLASSPATH && isKarateTest(testIdentifier); } + /** + * Returns whether reporting should defer to a dedicated Cucumber JVM Allure adapter for the given engine id. + * + * @param engine the JUnit Platform engine id + * @return {@code true} when a Cucumber 7 or Cucumber 8 Allure adapter is present and {@code engine} is cucumber + */ + static boolean shouldSkipCucumberEngine(final String engine) { + return (HAS_CUCUMBERJVM7_IN_CLASSPATH || HAS_CUCUMBERJVM8_IN_CLASSPATH) + && ENGINE_CUCUMBER.equals(engine); + } + private boolean isKarateTest(final TestIdentifier testIdentifier) { return getParents(testIdentifier).stream() .map(TestIdentifier::getSource) diff --git a/allure-junit-platform/src/test/java/io/qameta/allure/cucumber8jvm/AllureCucumber8Jvm.java b/allure-junit-platform/src/test/java/io/qameta/allure/cucumber8jvm/AllureCucumber8Jvm.java new file mode 100644 index 000000000..ff12bcf62 --- /dev/null +++ b/allure-junit-platform/src/test/java/io/qameta/allure/cucumber8jvm/AllureCucumber8Jvm.java @@ -0,0 +1,25 @@ +/* + * Copyright 2016-2026 Qameta Software Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.qameta.allure.cucumber8jvm; + +/** + * Classpath marker that represents the dedicated Cucumber 8 adapter in JUnit Platform integration tests. + */ +public final class AllureCucumber8Jvm { + + private AllureCucumber8Jvm() { + } +} diff --git a/allure-junit-platform/src/test/java/io/qameta/allure/junitplatform/AllureJunitPlatformTest.java b/allure-junit-platform/src/test/java/io/qameta/allure/junitplatform/AllureJunitPlatformTest.java index 708856bac..62a6b9e7a 100644 --- a/allure-junit-platform/src/test/java/io/qameta/allure/junitplatform/AllureJunitPlatformTest.java +++ b/allure-junit-platform/src/test/java/io/qameta/allure/junitplatform/AllureJunitPlatformTest.java @@ -416,6 +416,18 @@ void shouldProcessDynamicTests() { .containsExactlyInAnyOrder("testA", "testB", "testC"); } + /** + * Ensures Cucumber scenarios stay with the dedicated Cucumber 8 adapter when both that adapter and the + * JUnit Platform listener are present. + */ + @Test + @Issue("1497") + @Description + void shouldSkipCucumberEngineWhenAllureCucumber8IsPresent() { + assertThat(AllureJunitPlatform.shouldSkipCucumberEngine("cucumber")).isTrue(); + assertThat(AllureJunitPlatform.shouldSkipCucumberEngine("junit-jupiter")).isFalse(); + } + /** * Ensures the dedicated Karate adapter remains the only reporter for Karate scenarios while ordinary Jupiter * tests from the same class are still reported by the JUnit Platform integration. diff --git a/allure-junit4/src/main/java/io/qameta/allure/junit4/AllureJunit4.java b/allure-junit4/src/main/java/io/qameta/allure/junit4/AllureJunit4.java index bc348df0a..00df6835e 100644 --- a/allure-junit4/src/main/java/io/qameta/allure/junit4/AllureJunit4.java +++ b/allure-junit4/src/main/java/io/qameta/allure/junit4/AllureJunit4.java @@ -68,6 +68,8 @@ public class AllureJunit4 extends RunListener { private static final boolean HAS_CUCUMBERJVM7_IN_CLASSPATH = isClassAvailableOnClasspath("io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"); + private static final boolean HAS_CUCUMBERJVM8_IN_CLASSPATH = isClassAvailableOnClasspath("io.qameta.allure.cucumber8jvm.AllureCucumber8Jvm"); + /** * The method name JUnit 4 gives the synthetic test it reports when a runner cannot be built for a class. */ @@ -448,7 +450,8 @@ private static boolean isInitializationError(final Description description) { } private boolean shouldIgnore(final Description description) { - return HAS_CUCUMBERJVM7_IN_CLASSPATH && AllureJunit4Utils.isCucumberTest(description); + return (HAS_CUCUMBERJVM7_IN_CLASSPATH || HAS_CUCUMBERJVM8_IN_CLASSPATH) + && AllureJunit4Utils.isCucumberTest(description); } private static boolean isClassAvailableOnClasspath(final String clazz) { diff --git a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java index 72a81fb28..c00b1ac4e 100644 --- a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java +++ b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java @@ -142,6 +142,8 @@ public class AllureTestNg private static final boolean HAS_CUCUMBERJVM7_IN_CLASSPATH = isClassAvailableOnClasspath("io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"); + private static final boolean HAS_CUCUMBERJVM8_IN_CLASSPATH = isClassAvailableOnClasspath("io.qameta.allure.cucumber8jvm.AllureCucumber8Jvm"); + private static final boolean HAS_LISTENER_COMPARATOR = isClassAvailableOnClasspath("org.testng.ListenerComparator"); /** @@ -504,7 +506,7 @@ protected boolean shouldSkipReportingFor(final ITestResult testResult) { } final Set groupsSet = new HashSet<>(Arrays.asList(groups)); - return HAS_CUCUMBERJVM7_IN_CLASSPATH && groupsSet.contains("cucumber"); + return (HAS_CUCUMBERJVM7_IN_CLASSPATH || HAS_CUCUMBERJVM8_IN_CLASSPATH) && groupsSet.contains("cucumber"); } protected void startTest(final ITestResult testResult,