2

I have a Step Definitions file with 11 methods--each of which is a @Given, @When or @Then method. Two types of things are being tested, Feature1 things and Feature2 things. Later on there will be Feature3 things, Feature4 things, and so on. Right now, while complexity and sheer size are small, I want to get the "things" associated with Feature1 into StepsFile1, and the things associated with Feature2 into StepsFile2. And the things (variables and methods) that are common between the two need to go SOMEWHERE. StepsFileZero?? Cucumber requires a particular Step Definition to appear only once--no duplicates. I don't want dupicates anyway. Are there references or resources for me and this situation?

The person at this link (http://grokbase.com/t/gg/cukes/12bk4kx7m0/cucumber-jvm-what-is-the-best-way-to-split-up-a-large-step-definition-class) seems to have had the same question, but the couple of links in the answers were dead ends as there was a site migration from GitHub/cucumber to cucumber.io.

  • 2
    Coupling step files to feature files has been dubbed an [antipattern](https://github.com/cucumber/cucumber/wiki/Feature-Coupled-Step-Definitions-%28Antipattern%29), with the alternative suggestion to separate your steps by domain concept. – Atreys Apr 25 '16 at 19:27

1 Answers1

0

Just define a step class that contains steps used in various features and the declare it's package in your Runner for every feature you will need it. This will get a little bit more complicated if you have data shared between your steps. Let's say you have a shared step that collects user data and different Then-steps will have to evaluate this data. Since cucumber does not allow heritage you have tgo inject the data object in both step classes. One defines the user's data and the other will evaluate it.

Jefe infiltrado
  • 364
  • 2
  • 15