Search code examples
automationcucumberbddgherkinscenarios

How many steps(Gherkin lines) in a scenario in cucumber BDD should have?


As there is no restriction on number of lines(Steps/Gherkin) that a scenario should have , but still did anybody face issues in having more number of steps in a scenario (may be 15 or 20 steps) . Is anywhere it mentioned that using particular number of lines is a good practice? (Some reference would be helpful for me to show as a proof)

Thanks Sudhir


Solution

  • There is no restriction regarding the number of lines in a Gherkin scenario. At least no technical limitations.

    The limitation is rather understandability. Is it easy or is it hard to understand and maintain? This is a very subjective measurement. This is the very same limitation as with code. Is a method easy or hard to understand and maintain? Some people, including me, feel uncomfortable when a method does many things and is longer than a handful lines of code. Some people happily deliver methods that are many hundreds of lines of code.

    I did a write up from a podcast where some of the maintainers of Cucumber discuss BDD anti-patterns. It may serve you as a source to refer to. http://www.thinkcode.se/blog/2016/06/22/cucumber-antipatterns

    The original podcast can be found here: https://cucumber.io/blog/2016/05/09/cucumber-antipatterns

    Unfortunately, your question is about opinions and we know that opinions vary a lot.