Writing Gherkin with certain rules in mind can provide a nice foundation for understanding the right ways to write it so it becomes a little easier to recognize some of the bad practices.
1. The Golden Rule
The first rule is the golden rule and as the name would suggest, it’s very similar to the traditional golden rule in that we should write our Gherkin scenarios in much the same way we would expect others to write them for us. In essence, we want to make sure that everyone on the team can intuitively understand what the content of our scenarios is.
Since one of the main objectives of behavior-driven development is for us to bridge the communication gap between business and technology, we need everyone on the team to collaborate and to be fully engaged, leading to scenarios that everyone can understand.
2. The Cardinal Rule
The next rule is the Cardinal Rule. This is really probably the most important rule. At its most basic, it states that one scenario should cover exactly one single, independent behavior. We simply don’t want to have scenarios that have a whole bunch of behaviors piled into them. While it might seem efficient at some level to have these really long, end-to-end scenarios, it really confuses things. The lack of concision also leads to lack of clarity, and it becomes much more difficult to maintain. Keep it simple and make sure there’s one single, independent behavior in each of your scenarios. No more.
3. The Unique Example Rule
Then the final rule is the Unique Example Rule.
Essentially, you want to hit all of your boundary conditions. But after you’ve done that, you’re done. There’s no need to test the full universe of possibilities as that would result in a lot of unnecessary testing. The Unique Example Rule stipulates that we should avoid test duplication, that you don’t need to “test all the things.”
If you follow these three rules for writing good Gherkin, you’ll largely be able to avoid a lot of the anti-patterns.
Learn more about Gherkin writing and Behavior-Driven Development – watch this full presentation.
Contact us to schedule a custom private workshop on Gherkin and other Agile topics.