From 516506422afca06053900eccf34ba1d823abdabd Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sun, 26 May 2024 03:36:03 +0200 Subject: [PATCH 1/2] Include pickle name if parameterized --- .../core/plugin/TeamCityPluginTest.java | 10 ++++++---- .../messages/GherkinMessagesExample.java | 19 +++++++++++++++++-- .../messages/GherkinMessagesExamples.java | 9 +++++++-- .../messages/GherkinMessagesFeature.java | 4 ++-- .../gherkin/messages/GherkinMessagesRule.java | 4 ++-- .../GherkinMessagesScenarioOutline.java | 6 ++++-- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java index e965d469ed..71e49a7156 100755 --- a/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java +++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java @@ -72,7 +72,7 @@ void should_handle_scenario_outline() { "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:5' name = 'examples name']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location - + "path/test.feature:7' name = 'Example #1.1']\n" + + + "path/test.feature:7' name = 'Example #1.1 - name 1']\n" + "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" + @@ -83,9 +83,10 @@ void should_handle_scenario_outline() { "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'second step']\n" + "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" + - "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.1']\n" + + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.1 - name 1']\n" + + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location - + "path/test.feature:8' name = 'Example #1.2']\n" + + + "path/test.feature:8' name = 'Example #1.2 - name 2']\n" + "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" + @@ -96,7 +97,8 @@ void should_handle_scenario_outline() { "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'third step']\n" + "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" + - "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.2']\n" + + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.2 - name 2']\n" + + "##teamcity[customProgressStatus testsCategory = '' count = '0' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'examples name']\n" + diff --git a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java index 5a38fa1bd7..59385694e3 100644 --- a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java +++ b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java @@ -8,12 +8,16 @@ final class GherkinMessagesExample implements Node.Example { + private final GherkinMessagesFeature feature; private final TableRow tableRow; private final int examplesIndex; private final int rowIndex; private final Node parent; - GherkinMessagesExample(Node parent, TableRow tableRow, int examplesIndex, int rowIndex) { + GherkinMessagesExample( + GherkinMessagesFeature feature, Node parent, TableRow tableRow, int examplesIndex, int rowIndex + ) { + this.feature = feature; this.parent = parent; this.tableRow = tableRow; this.examplesIndex = examplesIndex; @@ -32,7 +36,18 @@ public Optional getKeyword() { @Override public Optional getName() { - return Optional.of("Example #" + examplesIndex + "." + rowIndex); + String pickleName = feature.getPickleAt(this).getName(); + boolean parameterized = !parent.getParent() + .filter(GherkinMessagesScenarioOutline.class::isInstance) + .flatMap(Node::getName) + .map(pickleName::equals) + .orElse(true); + + StringBuilder builder = new StringBuilder("Example #" + examplesIndex + "." + rowIndex); + if (parameterized) { + builder.append(" - ").append(pickleName); + } + return Optional.of(builder.toString()); } @Override diff --git a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExamples.java b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExamples.java index fda9d54964..1c7a4a0ef1 100644 --- a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExamples.java +++ b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExamples.java @@ -11,18 +11,23 @@ final class GherkinMessagesExamples implements Node.Examples { + private final GherkinMessagesFeature feature; private final io.cucumber.messages.types.Examples examples; private final List children; private final Location location; private final Node parent; - GherkinMessagesExamples(Node parent, io.cucumber.messages.types.Examples examples, int examplesIndex) { + GherkinMessagesExamples( + GherkinMessagesFeature feature, Node parent, io.cucumber.messages.types.Examples examples, int examplesIndex + ) { + this.feature = feature; this.parent = parent; this.examples = examples; this.location = GherkinMessagesLocation.from(examples.getLocation()); AtomicInteger row = new AtomicInteger(1); this.children = examples.getTableBody().stream() - .map(tableRow -> new GherkinMessagesExample(this, tableRow, examplesIndex, row.getAndIncrement())) + .map(tableRow -> new GherkinMessagesExample(feature, this, tableRow, examplesIndex, + row.getAndIncrement())) .collect(Collectors.toList()); } diff --git a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesFeature.java b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesFeature.java index dce72f94ae..c2f2e36fd8 100644 --- a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesFeature.java +++ b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesFeature.java @@ -46,12 +46,12 @@ final class GherkinMessagesFeature implements Feature { private Node mapRuleOrScenario(FeatureChild featureChild) { if (featureChild.getRule().isPresent()) { - return new GherkinMessagesRule(this, featureChild.getRule().get()); + return new GherkinMessagesRule(this, this, featureChild.getRule().get()); } io.cucumber.messages.types.Scenario scenario = featureChild.getScenario().get(); if (!scenario.getExamples().isEmpty()) { - return new GherkinMessagesScenarioOutline(this, scenario); + return new GherkinMessagesScenarioOutline(this, this, scenario); } return new GherkinMessagesScenario(this, scenario); } diff --git a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesRule.java b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesRule.java index c42c378317..1c6b495d0a 100644 --- a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesRule.java +++ b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesRule.java @@ -15,7 +15,7 @@ final class GherkinMessagesRule implements Node.Rule { private final io.cucumber.messages.types.Rule rule; private final List children; - GherkinMessagesRule(Node parent, io.cucumber.messages.types.Rule rule) { + GherkinMessagesRule(GherkinMessagesFeature feature, Node parent, io.cucumber.messages.types.Rule rule) { this.parent = parent; this.rule = rule; this.children = rule.getChildren().stream() @@ -24,7 +24,7 @@ final class GherkinMessagesRule implements Node.Rule { .map(Optional::get) .map(scenario -> { if (!scenario.getExamples().isEmpty()) { - return new GherkinMessagesScenarioOutline(this, scenario); + return new GherkinMessagesScenarioOutline(feature, this, scenario); } else { return new GherkinMessagesScenario(this, scenario); } diff --git a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesScenarioOutline.java b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesScenarioOutline.java index b34180c013..26d6c4bd40 100644 --- a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesScenarioOutline.java +++ b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesScenarioOutline.java @@ -15,12 +15,14 @@ final class GherkinMessagesScenarioOutline implements Node.ScenarioOutline { private final List children; private final Node parent; - GherkinMessagesScenarioOutline(Node parent, io.cucumber.messages.types.Scenario scenario) { + GherkinMessagesScenarioOutline( + GherkinMessagesFeature feature, Node parent, io.cucumber.messages.types.Scenario scenario + ) { this.parent = parent; this.scenario = scenario; AtomicInteger examplesIndex = new AtomicInteger(1); this.children = scenario.getExamples().stream() - .map(examples -> new GherkinMessagesExamples(this, examples, examplesIndex.getAndIncrement())) + .map(examples -> new GherkinMessagesExamples(feature, this, examples, examplesIndex.getAndIncrement())) .collect(Collectors.toList()); } From adb5b10d952b1ca0791f1de0fdc19fdc7f471ddf Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sun, 26 May 2024 15:05:11 +0200 Subject: [PATCH 2/2] Drop example to reduce verbosity and avoid language issues --- .../java/io/cucumber/core/plugin/TeamCityPluginTest.java | 8 ++++---- .../core/gherkin/messages/GherkinMessagesExample.java | 2 +- .../cucumber/core/gherkin/messages/FeatureParserTest.java | 2 +- .../junit/platform/engine/FeatureResolverTest.java | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java b/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java index 71e49a7156..12d09242b8 100755 --- a/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java +++ b/cucumber-core/src/test/java/io/cucumber/core/plugin/TeamCityPluginTest.java @@ -72,7 +72,7 @@ void should_handle_scenario_outline() { "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:5' name = 'examples name']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location - + "path/test.feature:7' name = 'Example #1.1 - name 1']\n" + + + "path/test.feature:7' name = '#1.1 - name 1']\n" + "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" + @@ -83,10 +83,10 @@ void should_handle_scenario_outline() { "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'second step']\n" + "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" + - "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.1 - name 1']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.1 - name 1']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location - + "path/test.feature:8' name = 'Example #1.2 - name 2']\n" + + + "path/test.feature:8' name = '#1.2 - name 2']\n" + "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" + @@ -97,7 +97,7 @@ void should_handle_scenario_outline() { "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'third step']\n" + "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" + - "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1.2 - name 2']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '#1.2 - name 2']\n" + "##teamcity[customProgressStatus testsCategory = '' count = '0' timestamp = '1970-01-01T12:00:00.000+0000']\n" + diff --git a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java index 59385694e3..c73dd9c9cd 100644 --- a/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java +++ b/cucumber-gherkin-messages/src/main/java/io/cucumber/core/gherkin/messages/GherkinMessagesExample.java @@ -43,7 +43,7 @@ public Optional getName() { .map(pickleName::equals) .orElse(true); - StringBuilder builder = new StringBuilder("Example #" + examplesIndex + "." + rowIndex); + StringBuilder builder = new StringBuilder("#" + examplesIndex + "." + rowIndex); if (parameterized) { builder.append(" - ").append(pickleName); } diff --git a/cucumber-gherkin-messages/src/test/java/io/cucumber/core/gherkin/messages/FeatureParserTest.java b/cucumber-gherkin-messages/src/test/java/io/cucumber/core/gherkin/messages/FeatureParserTest.java index ca6f8feea6..bb8d25fd08 100644 --- a/cucumber-gherkin-messages/src/test/java/io/cucumber/core/gherkin/messages/FeatureParserTest.java +++ b/cucumber-gherkin-messages/src/test/java/io/cucumber/core/gherkin/messages/FeatureParserTest.java @@ -83,7 +83,7 @@ void unnamed_elements_return_empty_strings_as_name() throws IOException { Node.Example example = examples.elements().iterator().next(); // Example is the exception. - assertEquals(Optional.of("Example #1.1"), example.getName()); + assertEquals(Optional.of("#1.1"), example.getName()); assertEquals(Optional.empty(), example.getKeyword()); } } 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..2e329ddc99 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 @@ -133,7 +133,7 @@ private TestDescriptor getOutline() { @Test void example() { TestDescriptor example = getExample(); - assertEquals("Example #1.1", example.getDisplayName()); + assertEquals("#1.1", example.getDisplayName()); assertEquals( asSet(create("FeatureTag"), create("Example1Tag"), create("ScenarioOutlineTag")), example.getTags()); @@ -157,7 +157,7 @@ void longNames() { JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, "long"); TestDescriptor example = getExample(); - assertEquals("A feature with scenario outlines - A scenario outline - With some text - Example #1.1", + assertEquals("A feature with scenario outlines - A scenario outline - With some text - #1.1", example.getDisplayName()); } @@ -178,7 +178,7 @@ void shortNamesWithExampleNumbers() { JUNIT_PLATFORM_SHORT_NAMING_STRATEGY_EXAMPLE_NAME_PROPERTY_NAME, "number"); TestDescriptor example = getExample(); - assertEquals("Example #1.1", example.getDisplayName()); + assertEquals("#1.1", example.getDisplayName()); } @Test