Cucumber sentence autocomplete



  • I have a difficulty with writing Cucumber tests. The re-usability of the Cucumber sentences is not consistent - I would like to avoid code duplication when creating sentences and methods glued to the sentences.

    Using the Cucumber's built in tool does not work as it slows Eclipse so badly. How to reuse code in an efficient way?

    For ex. I have the following Cucumber test in one suite:

    Scenario:
      Given As a full right user
      When I open the webpage
      Then I see the edit button
    

    And another one in another suite:

    Scenario:
      Given As a full right user
      When I open the webpage
      Then I can remove a user
    

    Not two, but having hundreds of tests, how can I handle the methods and cucumber scenarios of duplication? Duplication like I open the webpage and I load the webpage meaning the same, working in teams and because having hundreds of tests one may not notice that the method/sentence already exists.



  • An autocomplete would come against Cucumber's goal of creating a shared vocabulary.

    When the Three Amigos come to work on a new feature and its scenarios, they would develop this vocabulary, which mitigates the chances duplicated vocabulary. Keeping scenarios short and use proper mocking also helps.

    If you need to send parameters to a step definition, you can use Expressions:

    @Given("I have {int} cukes in my belly")
    public void i_have_n_cukes_in_my_belly(int cukes) {
    }
    
    Given I have 0 cukes in my belly
    Then I am hungry
    
    Given I have 50 cukes in my belly
    Then I am bloated
    
    Given I have 5 cukes in my belly
    Then I am satisfied
    

    If you want to compose steps, you can simply call using Cuke4Cuke:

    Given I eat a regular meal
    Then I am satisfied
    
     @Given("I eat a regular meal")
     public void i_eat_regular_meal() {
       Given("I have 5 cukes in my belly");
       Given("I drink a cup of coffee");
     }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2