Skip to content

[JUnit Platform Engine] Add Surefire naming strategy #3003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 29, 2025

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented May 29, 2025

⚡️ What's your motivation?

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!

Like wise the xml report by Surefire includes the name twice.

<testcase name="Belly - a few cukes" classname="Belly" time="0.06">

By using the cucumber.junit-platform.naming-strategy=surefire property when configuring surefire tests will look pretty in surefire too.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.5.2</version>
    <configuration>
        <properties>
            <!-- Work around. Surefire does not include enough
                 information to disambiguate between different
                 examples and scenarios. -->
            <configurationParameters>
                cucumber.junit-platform.naming-strategy=surefire
            </configurationParameters>
        </properties>
    </configuration>
</plugin>

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!

And

<testcase name="a few cukes" classname="Belly" time="0.059">

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

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
<testcase name="Belly - a few cukes" classname="Belly" time="0.06">
    <failure type="java.lang.AssertionError"><![CDATA[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)
]]></failure>
```

By using the `cucumber.junit-platform.naming-strategy=surefire` property
when configuring surefire tests will look pretty in surefire too.

```xml
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.5.2</version>
    <configuration>
        <properties>
            <!-- Work around. Surefire does not include enough
                 information to disambiguate between different
                 examples and scenarios. -->
            <configurationParameters>
                cucumber.junit-platform.naming-strategy=surefire
            </configurationParameters>
        </properties>
    </configuration>
</plugin>
```

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
<testcase name="a few cukes" classname="Belly" time="0.059">
    <failure message="TODO" type="java.lang.AssertionError"><![CDATA[java.lang.AssertionError: TODO
	at io.cucumber.skeleton.StepDefinitions.I_have_cukes_in_my_belly(StepDefinitions.java:10)
	at ✽.I have 42 cukes in my belly(classpath:io/cucumber/skeleton/belly.feature:4)
]]></failure>
```
@mpkorstanje mpkorstanje force-pushed the feature/add-surefire-strategy branch from ccfbd91 to 9c929f3 Compare May 29, 2025 16:14
@mpkorstanje mpkorstanje merged commit 7b9e895 into main May 29, 2025
6 checks passed
@mpkorstanje mpkorstanje deleted the feature/add-surefire-strategy branch May 29, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant