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

Invalid duplicated methods suggested as snippets for step definitions #1930

Closed
LorenzoBettini opened this issue Mar 28, 2020 · 6 comments
Closed
Labels
🐛 bug Defect / Bug

Comments

@LorenzoBettini
Copy link

Describe the bug
When you run a JUnit 4 test given a feature file with no step definitions implemented yet, Cucumber generates snippets for methods that are duplicate in the presence of steps with captured regular expressions (which can be implemented with a single method).

To Reproduce

Take this simple feature file, where the first two steps differ only for the string literals.

Feature: a feature

  Scenario: a scenario
    Given element with name "first a name"
    And element with name "another name"
    When something happens

and run a test case annotate with @RunWith(Cucumber.class) you get this output from Cucumber:

1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.110s


You can implement missing steps with the snippets below:

@Given("element with name {string}")
public void element_with_name(String string) {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}

@Given("element with name {string}")
public void element_with_name(String string) {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}

@When("something happens")
public void something_happens() {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java.PendingException();
}

The two proposed methods public void element_with_name(String string) are duplicate.
This did not happen with Cucumber 4 (currently I'm using version 5.5.0): only a public void element_with_name(String string) was suggested (and indeed adverbs like Given and And are not taken into consideration when executing step definitions).

Expected behavior

The proposed method snippets should be as follows (which is also what Cucumber 4.8.1 used to propose):

@Given("element with name {string}")
public void element_with_name(String string) {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("something happens")
public void something_happens() {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

The first method is used at runtime for both When and And steps.

Context & Motivation

With Cucumber 4 you could simply copy and paste the proposed methods in a Java file as a starting point. Now, you get a compiler error because of duplicated methods.

Your Environment

  • Versions used [e.g 5.5.0]
  • Linux Ubuntu 10.10
  • Build tool [e.g. Apache Maven 3.6.3, but also from Eclipse with the Cucumber plugin version 1.0.0]
@LorenzoBettini LorenzoBettini added the 🐛 bug Defect / Bug label Mar 28, 2020
@mpkorstanje
Copy link
Contributor

Cheers!

@LorenzoBettini
Copy link
Author

WOW! That was fast, thanks!
Do you have any plan of releasing this fixed version in the near future?

@LorenzoBettini
Copy link
Author

But... isn't there any test in the commit which fixes this issue?

@mpkorstanje
Copy link
Contributor

That needs a bit more refactoring to make it testable. This is one of the oldest classes in Cucumber. Checked it by hand for now.

@LorenzoBettini
Copy link
Author

@mpkorstanje and is there any estimation about the release of this fixed version?

@mpkorstanje
Copy link
Contributor

We don't do estimates. Releases are made when convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants