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: 
  1. Keeping all step definitions in a single class file. This approach quickly becomes impractical with more features
  2. Having separate classes. Now you have a new problem - wiring the instances of those classes together.
  3. One Class per Feature file - This is good  and also the most common approach except that how would you handle reusable step definitions
  4. 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.
  5. Step Definition file for each domain concept - This solves the problem of tightly coupled step definitions and keep them logically separated.
  6. 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

Popular posts from this blog

Software Testing @ Microsoft

RPA - Blue Prism, OpenSpan, Automation Anywhere vs UIPath