Skip to content
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

Support configurable NamingStrategy.ExampleName #32

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Apr 5, 2024

🤔 What's changed?

Support configurable NamingStrategy.ExampleName

For example:

public final class MyJUnitXmlFormatter implements ConcurrentEventListener {

    private final MessagesToJunitXmlWriter writer;

    public JUnitFormatter(OutputStream out) {
        this.writer = new MessagesToJunitXmlWriter(NamingStrategy.ExampleName.PICKLE, out);
    }

    @Override
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(Envelope.class, this::write);
    }

    private void write(Envelope event) {
        try {
            writer.write(event);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

        if (event.getTestRunFinished().isPresent()) {
            try {
                writer.close();
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }

}

Note: Cucumber-JVM at present doesn't allow much configuration of plugins. To take advantage of this new option, the class above must be copied. And can be used in Cucumber-JVM with
cucumber.plugin=com.example.MyJUnitXmlFormatter:target/report.xml.

Fixes: #27

🏷️ 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.

For example:

```java
public final class MyJUnitXmlFormatter implements ConcurrentEventListener {

    private final MessagesToJunitXmlWriter writer;

    public JUnitFormatter(OutputStream out) {
        this.writer = new MessagesToJunitXmlWriter(NamingStrategy.ExampleName.PICKLE, out);
    }

    @OverRide
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(Envelope.class, this::write);
    }

    private void write(Envelope event) {
        try {
            writer.write(event);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

        if (event.getTestRunFinished().isPresent()) {
            try {
                writer.close();
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }

}
```

Note: Cucumber-JVM at present doesn't allow much configuration of plugins.
To take advantage of this new option, the class above must be copied. And
can be used in Cucumber-JVM with
`cucumber.plugin=com.example.MyJUnitXmlFormatter:target/report.xml`.

Fixes: #27
@mpkorstanje mpkorstanje marked this pull request as ready for review April 5, 2024 15:29
@mpkorstanje mpkorstanje merged commit 6f6acc7 into main Apr 5, 2024
3 checks passed
@mpkorstanje mpkorstanje deleted the configure-example-names branch April 5, 2024 15:36
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.

Wrong test name in XML report when running Scenario Outline
1 participant