But scenarios are not suitable for reuse regardless of what form they have. They are meant as acceptance criteria - examples that explain requirements. Just like programs are not meant to be reused to construct larger programs.
I donât believe any part of this is true.
Iâd say in fact, that more than half of requirements I get every day will be stories that naturally fork from existing scenarios. When I buy golf clubs, that forks off a scenario where Iâve added them to the shopping cart. The conversations I have with stakeholders also center around this.
Building executable specifications in a language that doesnât allow this is, in my opinion, a massive impediment to doing BDD. A library of well tested, precisely defined scenarios that are easily referred to serves as a great jumping off point for conversations about new features and new scenarios. Why not use those scenarios as a basis for new scenarios?
Anyone writing automated checks in Gherkin rather than requirements, should just stop doing that. It is pointless.
I agree, but this isnât about that.
Either practice BDD so that the Gherkin format is useful or it makes no sense to use Gherkin. It seems most of the issues with Gherkin are the result of using it for something that it is not meant for, much like using a hammer to drive in a screw.
It is the hammerâs fault though. The lack of this feature doesnât just make test writing harder, it makes BDD harder.
Without inheritance in Gherkin you are pushed into pushing what end up being potentially important details of the specification in the imperative step code - when you âlog in as userâ you simply canât squeeze every potentially relevant detail in that step without repeating yourself a lot.
This actually causes a lot of stakeholders to lose interest in even looking at these stories. They end up being too vague to be useful to them and you lose the ability to have conversations around behavior with them. This happens a lot.
The alternative - where you have a âclickâ step and a âenter text in textboxâ scenario, is that you have a lot of very repetitive scenarios that are extremely annoying to maintain and are potentially far too detailed for stakeholders to be interested in them.
If you do have inheritance, I find this approach works fantastically well, though. The conversation centers around the forked scenario and the parent scenario is abstracted away, the stakeholder can still refer to it if necessary - the best of all BDD worlds.
The Gherkin alternative I built, for those who are interested (itâs based upon strongly typed YAML, stories are supposed to inherit, youâre encouraged to have reusable steps like âclickâ and âenter textâ and you can generate documentation from it which you can use to trick grumpy stakeholders into doing BDD with):
Log in as James:
given:
browser: firefox # test preconditions
steps:
- Enter text:
username: james
password: password
- Click: log in
- Should appear: dashboard
See James analytics:
based on: log in as james # test inheritance
following steps:
- Click: analytics
- Should appear: analytics dashboard
People who have a programming background often lack the testing insight.
What specific insight do you think Iâm missing here?