Skip to content

Remove framework elements from UndefinedStepException stacktrace #3002

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 1 commit into from
May 29, 2025

Conversation

mpkorstanje
Copy link
Contributor

🤔 What's changed?

Stack traces for the UndefinedStepException now look like this:

io.cucumber.junit.platform.engine.UndefinedStepException:
The step 'I have 42 cukes in my belly' is undefined.
You can implement this step using the snippet(s) below:

@Given("I have {int} cukes in my belly")
public void i_have_cukes_in_my_belly(Integer int1) {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}

        at ✽.I have 42 cukes in my belly(classpath:io/cucumber/skeleton/belly.feature:4)

Where previously they included a long stacktrace.

        at io.cucumber.core.runtime.TestCaseResultObserver.assertTestCasePassed(TestCaseResultObserver.java:69)
        at io.cucumber.junit.platform.engine.TestCaseResultObserver.assertTestCasePassed(TestCaseResultObserver.java:22)
        at io.cucumber.junit.platform.engine.CucumberEngineExecutionContext.lambda$runTestCase$4(CucumberEngineExecutionContext.java:116)
        at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:136)
        at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
        at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:136)
        at io.cucumber.junit.platform.engine.CucumberEngineExecutionContext.runTestCase(CucumberEngineExecutionContext.java:111)
        at io.cucumber.junit.platform.engine.NodeDescriptor$PickleDescriptor.execute(NodeDescriptor.java:168)
        at io.cucumber.junit.platform.engine.NodeDescriptor$PickleDescriptor.execute(NodeDescriptor.java:90)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

🏷️ What kind of change is this?

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

♻️ Anything particular you want feedback on?

The implementation is not ideal. It effectively duplicates functionality from the io.cucumber.core.runner package, but we can't change that without breaking assumptions made by the plugin system.

📋 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.

@mpkorstanje mpkorstanje force-pushed the feature/trim-undefined-step-exception-stacktrace branch 5 times, most recently from aa6e9da to 9484d65 Compare May 23, 2025 15:18
Stack traces for the UndefinedStepException now look like this:

```
io.cucumber.junit.platform.engine.UndefinedStepException:
The step 'I have 42 cukes in my belly' is undefined.
You can implement this step using the snippet(s) below:

@given("I have {int} cukes in my belly")
public void i_have_cukes_in_my_belly(Integer int1) {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}

        at ✽.I have 42 cukes in my belly(classpath:io/cucumber/skeleton/belly.feature:4)
```

Where previously they included a long stacktrace.

```
        at io.cucumber.core.runtime.TestCaseResultObserver.assertTestCasePassed(TestCaseResultObserver.java:69)
        at io.cucumber.junit.platform.engine.TestCaseResultObserver.assertTestCasePassed(TestCaseResultObserver.java:22)
        at io.cucumber.junit.platform.engine.CucumberEngineExecutionContext.lambda$runTestCase$4(CucumberEngineExecutionContext.java:116)
        at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:136)
        at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
        at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:136)
        at io.cucumber.junit.platform.engine.CucumberEngineExecutionContext.runTestCase(CucumberEngineExecutionContext.java:111)
        at io.cucumber.junit.platform.engine.NodeDescriptor$PickleDescriptor.execute(NodeDescriptor.java:168)
        at io.cucumber.junit.platform.engine.NodeDescriptor$PickleDescriptor.execute(NodeDescriptor.java:90)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
```

The implementation is not ideal. It effectively duplicates functionality
from the `io.cucumber.core.runner` package, but we can't change that
without breaking assumptions made by the plugin system.
@mpkorstanje mpkorstanje force-pushed the feature/trim-undefined-step-exception-stacktrace branch from 9484d65 to 69b02c8 Compare May 23, 2025 15:20
@mpkorstanje mpkorstanje merged commit ba8ce7b into main May 29, 2025
6 checks passed
@mpkorstanje mpkorstanje deleted the feature/trim-undefined-step-exception-stacktrace branch May 29, 2025 16:16
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