From 9c929f3ec654a3fd7a932b57fcaf9b51b0f393ce Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Thu, 29 May 2025 18:09:58 +0200 Subject: [PATCH 1/5] [JUnit Platform Engine] Add Surefire naming strategy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When testing with Surefire using the `long` naming strategy the feature name is included in every error message twice. This can be quite annoying when the name is long. For example: ``` [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.103 s <<< FAILURE! -- in io.cucumber.skeleton.RunCucumberTest [ERROR] Belly.Belly - a few cukes -- Time elapsed: 0.060 s <<< FAILURE! java.lang.AssertionError: at io.cucumber.skeleton.StepDefinitions.I_have_cukes_in_my_belly(StepDefinitions.java:11) at ✽.I have 42 cukes in my belly(classpath:io/cucumber/skeleton/belly.feature:4) ``` Like wise the xml report by Surefire includes the name twice. ```xml ``` By using the `cucumber.junit-platform.naming-strategy=surefire` property when configuring surefire tests will look pretty in surefire too. ```xml org.apache.maven.plugins maven-surefire-plugin 3.5.2 cucumber.junit-platform.naming-strategy=surefire ``` For example: ``` [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.102 s <<< FAILURE! -- in io.cucumber.skeleton.RunCucumberTest [ERROR] Belly.a few cukes -- Time elapsed: 0.059 s <<< FAILURE! java.lang.AssertionError: TODO at io.cucumber.skeleton.StepDefinitions.I_have_cukes_in_my_belly(StepDefinitions.java: ``` And ```xml ``` --- CHANGELOG.md | 2 + .../resources/archetype-resources/pom.xml | 2 +- .../should-generate-project/reference/pom.xml | 2 +- cucumber-junit-platform-engine/README.md | 19 ++-- .../junit/platform/engine/Constants.java | 86 +++++++++++++------ .../engine/DefaultNamingStrategyProvider.java | 50 +++++++++++ .../platform/engine/FeatureResolverTest.java | 26 ++++++ examples/calculator-java-junit5/pom.xml | 2 +- examples/calculator-kotlin-junit5/pom.xml | 2 +- examples/spring-java-junit5/pom.xml | 2 +- 10 files changed, 154 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9f65fde7d..6c7eea06a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- [JUnit Platform Engine] Add surefire naming strategy ([#3003](https://github.com/cucumber/cucumber-jvm/pull/3003) M.P. Korstanje) ## [7.22.2] - 2025-05-12 ### Changed diff --git a/cucumber-archetype/src/main/resources/archetype-resources/pom.xml b/cucumber-archetype/src/main/resources/archetype-resources/pom.xml index a6a67d424d..cd5478f587 100644 --- a/cucumber-archetype/src/main/resources/archetype-resources/pom.xml +++ b/cucumber-archetype/src/main/resources/archetype-resources/pom.xml @@ -83,7 +83,7 @@ information to disambiguate between different examples and scenarios. --> - cucumber.junit-platform.naming-strategy=long + cucumber.junit-platform.naming-strategy=surefire diff --git a/cucumber-archetype/src/test/resources/projects/should-generate-project/reference/pom.xml b/cucumber-archetype/src/test/resources/projects/should-generate-project/reference/pom.xml index 0c47930704..8fbe6c740b 100644 --- a/cucumber-archetype/src/test/resources/projects/should-generate-project/reference/pom.xml +++ b/cucumber-archetype/src/test/resources/projects/should-generate-project/reference/pom.xml @@ -83,7 +83,7 @@ information to disambiguate between different examples and scenarios. --> - cucumber.junit-platform.naming-strategy=long + cucumber.junit-platform.naming-strategy=surefire diff --git a/cucumber-junit-platform-engine/README.md b/cucumber-junit-platform-engine/README.md index 7b23b13add..13799f8479 100644 --- a/cucumber-junit-platform-engine/README.md +++ b/cucumber-junit-platform-engine/README.md @@ -54,9 +54,11 @@ for a brief how to. Because Surefire and Gradle reports provide the results in a ` - ` format, only scenario names or example numbers are reported. This -can make for hard to read reports. To improve the readability of the reports -provide the `cucumber.junit-platform.naming-strategy=long` configuration -parameter. This will include the feature name as part of the test name. +can make for hard to read reports. + +To improve the readability of the reports provide the +`cucumber.junit-platform.naming-strategy` configuration parameter to +Gradle. This will include the feature name as part of the test name. ##### Maven @@ -68,7 +70,7 @@ parameter. This will include the feature name as part of the test name. - cucumber.junit-platform.naming-strategy=long + cucumber.junit-platform.naming-strategy=surefire @@ -416,7 +418,7 @@ cucumber.filter.tags= # a cucumber tag cucumber.glue= # comma separated package names. # example: com.example.glue -cucumber.junit-platform.naming-strategy= # long or short. +cucumber.junit-platform.naming-strategy= # long, short or surefire. # default: short # include parent descriptor name in test descriptor. @@ -429,6 +431,11 @@ cucumber.junit-platform.naming-strategy.long.example-name= # number or pickl # default: number # Use example number or pickle name for examples when # long naming strategy is used + +cucumber.junit-platform.naming-strategy.surefire.example-name= # number or pickle. + # default: number + # Use example number or pickle name for examples when + # surefire naming strategy is used cucumber.plugin= # comma separated plugin strings. # example: pretty, json:path/to/report.json @@ -615,7 +622,7 @@ Note: any files written by Cucumber will be overwritten during the rerun. information to disambiguate between different examples and scenarios. --> - cucumber.junit-platform.naming-strategy=long + cucumber.junit-platform.naming-strategy=surefire diff --git a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java index 06a6573e11..273e92009d 100644 --- a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java +++ b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java @@ -126,15 +126,20 @@ public final class Constants { /** * Property name used to configure the naming strategy: {@value} *

- * Value must be one of {@code long} or {@code short}. By default, short - * names are used. + * Value must be one of {@code long}, {@code short}, or {@code surefire}. By + * default, short names are used. *

- * When long names are used the parent descriptor names are included into - * each test descriptor name. So for example a single example would be - * named: + * When the {@code long} naming strategy is used all parent descriptor names + * are included in each test descriptor name. So for example a single + * example would be named: * {@code Feature Name - Rule Name - Scenario Name - Examples Name - Example #N }. - * This is useful for tools that only report the test name such as Maven and - * Gradle. + * This is useful for tools that only report the test name such as Gradle. + *

+ * When the {@code surefire} naming strategy is used nodes are named such + * that the Surefire makes sense. The feature name will be rendered as the + * class name. The long name without the feature will be rendered as the + * test\ method name. For example: + * {@code Feature Name.Rule Name - Scenario Name - Examples Name - Example #N }. */ @API(status = Status.EXPERIMENTAL, since = "7.0.0") public static final String JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME = "cucumber.junit-platform.naming-strategy"; @@ -143,36 +148,61 @@ public final class Constants { * Property name used to configure the naming strategy of examples in case * of short naming strategy: {@value} *

- * Value must be one of {@code number} or {@code pickle}. By default, - * numbers are used. - *

- * When set to {@code pickle} the pickle name is used. So for scenario name - * {@code Adding and } and example with params {@code a = 10} and - * {@code b = 20} the following name would be produced: + * Value must be one of {@code number}, {@code pickle}, or + * {@code number-and-pickle-if-parameterized}. By default, + * {@code number-and-pickle-if-parameterized} is used. + *

*/ @API(status = Status.EXPERIMENTAL, since = "7.16.2") public static final String JUNIT_PLATFORM_SHORT_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME = "cucumber.junit-platform.naming-strategy.short.example-name"; /** * Property name used to configure the naming strategy of examples in case - * of long naming strategy: {@value} - *

- * Value must be one of {@code number} or {@code pickle}. By default, - * numbers are used. + * of surefire naming strategy: {@value} *

- * When set to {@code pickle} the pickle name is used. So for scenario name - * {@code Adding and } and example with params {@code a = 10} and - * {@code b = 20} the following name would be produced: - * {@code Feature Name - Rule Name - Adding and - Examples Name - Adding 10 and 20}. + * Value must be one of {@code number}, {@code pickle}, or + * {@code number-and-pickle-if-parameterized}. By default, + * {@code number-and-pickle-if-parameterized} is used. + *

+ */ + @API(status = Status.EXPERIMENTAL, since = "7.23.0") + public static final String JUNIT_PLATFORM_SUREFIRE_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME = "cucumber.junit-platform.naming-strategy.surefire.example-name"; + + /** + * Property name used to configure the naming strategy of examples in case + * of long naming strategy: {@value} *

- * Using example numbers works well in all scenarios, but if parameterized - * scenario names are used consistently, the pickle name provides more - * clarity. + * Value must be one of {@code number}, {@code pickle}, or + * {@code number-and-pickle-if-parameterized}. By default, + * {@code number-and-pickle-if-parameterized} is used. + *

*/ @API(status = Status.EXPERIMENTAL, since = "7.16.2") public static final String JUNIT_PLATFORM_LONG_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME = "cucumber.junit-platform.naming-strategy.long.example-name"; diff --git a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java index b436fa4f78..812c054fde 100644 --- a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java +++ b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java @@ -11,6 +11,7 @@ import static io.cucumber.junit.platform.engine.Constants.JUNIT_PLATFORM_LONG_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME; import static io.cucumber.junit.platform.engine.Constants.JUNIT_PLATFORM_SHORT_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME; +import static io.cucumber.junit.platform.engine.Constants.JUNIT_PLATFORM_SUREFIRE_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME; enum DefaultNamingStrategyProvider { LONG { @@ -31,6 +32,16 @@ NamingStrategy create(ConfigurationParameters configuration) { .orElse(DefaultNamingStrategyProvider::exampleNumberStrategy) .apply(DefaultNamingStrategyProvider::shortStrategy); } + }, + + SUREFIRE { + @Override + NamingStrategy create(ConfigurationParameters configuration) { + return configuration.get(JUNIT_PLATFORM_SUREFIRE_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME) + .map(DefaultNamingStrategyProvider::parseStrategy) + .orElse(DefaultNamingStrategyProvider::exampleNumberStrategy) + .apply(DefaultNamingStrategyProvider::surefireStrategy); + } }; abstract NamingStrategy create(ConfigurationParameters configuration); @@ -100,4 +111,43 @@ private static String longStrategy(Node node, String currentNodeName) { return builder.toString(); } + + private static String surefireStrategy(Node node, String currentNodeName) { + // Surefire uses the parents of test nodes to determine the class name. + // As we want the class name to match the feature name we name the + // parents of the test containing nodes after the feature. + if (node instanceof Node.Examples || node instanceof Node.Rule) { + return nameOrKeyword(findFeature(node)); + } + // Scenarios and examples names are used by surefire to populate the + // testname. We want this to be long, but without the feature name + // because that will be used for the class name + if (node instanceof Node.Scenario || node instanceof Node.Example) { + return longStrategyWithoutFeatureName(node, currentNodeName); + } + // Everything else, can be short, will be ignored by surefire. + return shortStrategy(node, currentNodeName); + } + + private static String longStrategyWithoutFeatureName(Node node, String currentNodeName) { + StringBuilder builder = new StringBuilder(); + builder.append(currentNodeName); + node = node.getParent().orElse(null); + + while (node != null && !(node instanceof Node.Feature)) { + builder.insert(0, " - "); + builder.insert(0, nameOrKeyword(node)); + node = node.getParent().orElse(null); + } + return builder.toString(); + } + + private static Node findFeature(Node node) { + Node candidate = node.getParent().orElse(null); + while (candidate != null) { + node = candidate; + candidate = node.getParent().orElse(null); + } + return node; + } } diff --git a/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java b/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java index 88d4ad1cce..a5c17d96c8 100644 --- a/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java +++ b/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java @@ -130,6 +130,14 @@ private TestDescriptor getOutline() { return iterator.next(); } + private TestDescriptor getParameterizedOutline() { + Iterator iterator = getFeature().getChildren().iterator(); + iterator.next(); + iterator.next(); + iterator.next(); + return iterator.next(); + } + @Test void example() { TestDescriptor example = getExample(); @@ -191,6 +199,24 @@ void shortNamesWithPickleNames() { assertEquals("A scenario outline", example.getDisplayName()); } + @Test + void surefireNames() { + configurationParameters = new MapConfigurationParameters( + JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, "surefire"); + + TestDescriptor example = getExample(); + assertEquals("A scenario outline - With some text - Example #1.1", + example.getDisplayName()); + + TestDescriptor examples = example.getParent().get(); + assertEquals("A feature with scenario outlines", + examples.getDisplayName()); + + TestDescriptor feature = examples.getParent().get(); + assertEquals("A feature with scenario outlines", + examples.getDisplayName()); + } + private TestDescriptor getExample() { return getOutline().getChildren().iterator().next().getChildren().iterator().next(); } diff --git a/examples/calculator-java-junit5/pom.xml b/examples/calculator-java-junit5/pom.xml index c35b104f07..b3124dd818 100644 --- a/examples/calculator-java-junit5/pom.xml +++ b/examples/calculator-java-junit5/pom.xml @@ -92,7 +92,7 @@ - cucumber.junit-platform.naming-strategy=long + cucumber.junit-platform.naming-strategy=surefire diff --git a/examples/calculator-kotlin-junit5/pom.xml b/examples/calculator-kotlin-junit5/pom.xml index b7469eb5d9..9de2a8cd05 100644 --- a/examples/calculator-kotlin-junit5/pom.xml +++ b/examples/calculator-kotlin-junit5/pom.xml @@ -114,7 +114,7 @@ - cucumber.junit-platform.naming-strategy=long + cucumber.junit-platform.naming-strategy=surefire diff --git a/examples/spring-java-junit5/pom.xml b/examples/spring-java-junit5/pom.xml index 580766fc8b..c618e062d7 100644 --- a/examples/spring-java-junit5/pom.xml +++ b/examples/spring-java-junit5/pom.xml @@ -111,7 +111,7 @@ - cucumber.junit-platform.naming-strategy=long + cucumber.junit-platform.naming-strategy=surefire From 4764462f0f7f78916a49e4eac5ce530eccb18d87 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Thu, 29 May 2025 18:50:13 +0200 Subject: [PATCH 2/5] Update for number-and-pickle-if-parameterized --- cucumber-junit-platform-engine/README.md | 2 +- .../io/cucumber/junit/platform/engine/Constants.java | 10 +++++----- .../engine/DefaultNamingStrategyProvider.java | 2 +- .../junit/platform/engine/FeatureResolverTest.java | 8 ++++---- .../platform/engine/feature-with-outline.feature | 12 ++++++++++++ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cucumber-junit-platform-engine/README.md b/cucumber-junit-platform-engine/README.md index e3af466e7e..c5a8cfb0aa 100644 --- a/cucumber-junit-platform-engine/README.md +++ b/cucumber-junit-platform-engine/README.md @@ -433,7 +433,7 @@ cucumber.junit-platform.naming-strategy.long.example-name= # number, number- # long naming strategy is used cucumber.junit-platform.naming-strategy.surefire.example-name= # number or pickle. - # default: number + # default: number-and-pickle-if-parameterized # Use example number or pickle name for examples when # surefire naming strategy is used diff --git a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java index 273e92009d..7b257f515a 100644 --- a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java +++ b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java @@ -135,11 +135,11 @@ public final class Constants { * {@code Feature Name - Rule Name - Scenario Name - Examples Name - Example #N }. * This is useful for tools that only report the test name such as Gradle. *

- * When the {@code surefire} naming strategy is used nodes are named such - * that the Surefire makes sense. The feature name will be rendered as the - * class name. The long name without the feature will be rendered as the - * test\ method name. For example: - * {@code Feature Name.Rule Name - Scenario Name - Examples Name - Example #N }. + * When the {@code surefire} naming strategy is used nodes are named such that + * the Surefire output makes sense. The feature name will be rendered as the + * class name. The long name without the feature will be rendered as the test + * method name. For example: + * {@code Feature Name.Rule Name - Scenario Name - Examples Name - Example #N}. */ @API(status = Status.EXPERIMENTAL, since = "7.0.0") public static final String JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME = "cucumber.junit-platform.naming-strategy"; diff --git a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java index bb45aebcca..55508153b4 100644 --- a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java +++ b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DefaultNamingStrategyProvider.java @@ -39,7 +39,7 @@ NamingStrategy create(ConfigurationParameters configuration) { NamingStrategy create(ConfigurationParameters configuration) { return configuration.get(JUNIT_PLATFORM_SUREFIRE_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME) .map(DefaultNamingStrategyProvider::parseStrategy) - .orElse(DefaultNamingStrategyProvider::exampleNumberStrategy) + .orElse(DefaultNamingStrategyProvider::exampleNumberAndPickleIfParameterizedStrategy) .apply(DefaultNamingStrategyProvider::surefireStrategy); } }; diff --git a/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java b/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java index 019342a03e..24376d48e6 100644 --- a/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java +++ b/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java @@ -221,12 +221,12 @@ void shortNamesWithPickleNamesIfParameterized() { } @Test - void surefireNames() { + void surefireNamesWithPickleNamesIfParameterized() { configurationParameters = new MapConfigurationParameters( JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, "surefire"); - TestDescriptor example = getExample(); - assertEquals("A scenario outline - With some text - Example #1.1", + TestDescriptor example = getParametrizedExample(); + assertEquals("A scenario with - Examples - Example #1.1: A scenario with A", example.getDisplayName()); TestDescriptor examples = example.getParent().get(); @@ -235,7 +235,7 @@ void surefireNames() { TestDescriptor feature = examples.getParent().get(); assertEquals("A feature with scenario outlines", - examples.getDisplayName()); + feature.getDisplayName()); } private TestDescriptor getExample() { diff --git a/cucumber-junit-platform-engine/src/test/resources/io/cucumber/junit/platform/engine/feature-with-outline.feature b/cucumber-junit-platform-engine/src/test/resources/io/cucumber/junit/platform/engine/feature-with-outline.feature index f04d6ae671..46da5441de 100644 --- a/cucumber-junit-platform-engine/src/test/resources/io/cucumber/junit/platform/engine/feature-with-outline.feature +++ b/cucumber-junit-platform-engine/src/test/resources/io/cucumber/junit/platform/engine/feature-with-outline.feature @@ -48,3 +48,15 @@ Feature: A feature with scenario outlines | example | | A | | B | + + @ScenarioOutlineTag + Scenario Outline: A scenario with + Given a parameterized scenario outline + When it is executed + Then is used + + @Example1Tag + Examples: + | example | + | A | + | B | From df539d783f71734c2c42942d58c13723edcd222c Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Thu, 29 May 2025 18:50:25 +0200 Subject: [PATCH 3/5] Update for number-and-pickle-if-parameterized --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a6abc89b..c09696316e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - [JUnit Platform Engine, TestNG] Remove framework elements from `UndefinedStepException` stacktrace ([#3002](https://github.com/cucumber/cucumber-jvm/pull/3002) M.P. Korstanje) -- [JUnit Platform Engine] Add surefire naming strategy ([#3003](https://github.com/cucumber/cucumber-jvm/pull/3003) M.P. Korstanje) +- [JUnit Platform Engine] Add `surefire` naming strategy ([#3003](https://github.com/cucumber/cucumber-jvm/pull/3003) M.P. Korstanje) ## [7.22.2] - 2025-05-12 ### Changed From 35dabc7e5e757d13d3a558bf1a92b91866a7cc54 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Thu, 29 May 2025 18:52:18 +0200 Subject: [PATCH 4/5] Update for number-and-pickle-if-parameterized --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c09696316e..b02de3fadd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [JUnit Platform Engine, TestNG] Remove framework elements from `UndefinedStepException` stacktrace ([#3002](https://github.com/cucumber/cucumber-jvm/pull/3002) M.P. Korstanje) - [JUnit Platform Engine] Add `surefire` naming strategy ([#3003](https://github.com/cucumber/cucumber-jvm/pull/3003) M.P. Korstanje) +### Changed +- [JUnit Platform Engine] Use `number-and-pickle-if-parameterized ` example naming strategy by default ([#3004](https://github.com/cucumber/cucumber-jvm/pull/3004) M.P. Korstanje) + ## [7.22.2] - 2025-05-12 ### Changed - [Archetype] Assume new projects are created with at least Java 17 From 46dcc76a809d36707b222c774424941ff487d8a6 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Thu, 29 May 2025 19:04:54 +0200 Subject: [PATCH 5/5] Spotless --- .../io/cucumber/junit/platform/engine/Constants.java | 8 ++++---- .../junit/platform/engine/FeatureResolverTest.java | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java index 7b257f515a..0349498808 100644 --- a/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java +++ b/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java @@ -135,10 +135,10 @@ public final class Constants { * {@code Feature Name - Rule Name - Scenario Name - Examples Name - Example #N }. * This is useful for tools that only report the test name such as Gradle. *

- * When the {@code surefire} naming strategy is used nodes are named such that - * the Surefire output makes sense. The feature name will be rendered as the - * class name. The long name without the feature will be rendered as the test - * method name. For example: + * When the {@code surefire} naming strategy is used nodes are named such + * that the Surefire output makes sense. The feature name will be rendered + * as the class name. The long name without the feature will be rendered as + * the test method name. For example: * {@code Feature Name.Rule Name - Scenario Name - Examples Name - Example #N}. */ @API(status = Status.EXPERIMENTAL, since = "7.0.0") diff --git a/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java b/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java index 24376d48e6..14c018b2c2 100644 --- a/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java +++ b/cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/FeatureResolverTest.java @@ -225,17 +225,24 @@ void surefireNamesWithPickleNamesIfParameterized() { configurationParameters = new MapConfigurationParameters( JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, "surefire"); + // The test node gets the long name, without the feature name. TestDescriptor example = getParametrizedExample(); assertEquals("A scenario with - Examples - Example #1.1: A scenario with A", example.getDisplayName()); + // The parent node gets the feature name. TestDescriptor examples = example.getParent().get(); assertEquals("A feature with scenario outlines", examples.getDisplayName()); - TestDescriptor feature = examples.getParent().get(); + // Remaining nodes are named by their short names. + TestDescriptor scenarioOutline = examples.getParent().get(); + assertEquals("A scenario with ", + scenarioOutline.getDisplayName()); + + TestDescriptor feature = scenarioOutline.getParent().get(); assertEquals("A feature with scenario outlines", - feature.getDisplayName()); + feature.getDisplayName()); } private TestDescriptor getExample() {