Organize step definitions - Cucumber best practices
Problem: How do we organize step definitions in the BDD framework as they increase?
If you are using a BDD tool like Specflow/Cucumber/Jbehave you have to define your step definitions for the feature files. Let's look at different ways to do that:
Journey to Ideal way of organizing step definitions:
- Keeping all step definitions in a single class file. This approach quickly becomes impractical with more features
- Having separate classes. Now you have a new problem - wiring the instances of those classes together.
- One Class per Feature file - This is good and also the most common approach except that how would you handle reusable step definitions
- ReUsableSteps file - Once you recognize that a step is reused, move it to a class ReUsableSteps or something. This way, if a step does not exist in its class then it should be in ReUsableSteps.
- Step Definition file for each domain concept - This solves the problem of tightly coupled step definitions and keep them logically separated.
- Page Step Definitions - This is my favorite and is similar to the page object model being used for test automation. Loosely coupled step definitions that are logically separated.
Comments
Post a Comment