Hello World!
As you may have already guessed, the title of my post is influenced by Jonas Nicklas' blog post You're Cuking It Wrong. In this post and and a few others to follow, I will cover some more counter productive ways of using cucumber features that I have come across. And in this post I will show how brevity of a cucumber feature may seem appealing to a novice BDD/cucumber developer and how they end up ignoring the collaboration and communication benefits. Lets get started with an example
Does that look alright? The steps read reasonably well, with the exception of the angle brackets(<>). Now lets read the 'Given' step along with examples, ie; by substituting the variables from the 'Examples:' section.
They all read well in isolation but, the last example above changes the meaning of the step template completely from
to
And clearly it creates a lot of confusion, if the examples change the meaning of the scenario itself.
So how does anyone end up writing a scenario like that?Well, there was a phase in my cucumber learning when I knew only about 'Scenario's and was unaware of the 'Scenario Outline's. So with my limited knowledge, if I were to write scenarios for the above feature, I would have ended up with quite a few scenarios like
And so on. That is hard, quite a bit of duplication and a maintenance nightmare. Then there is the sudden enlightenment of 'Scenario Outline's and I start refactoring my scenarios to be something like below.
Now the gold card and silver card looks so similar that I feel like combining them.
That looks even better and I cannot resist my temptation remove some more duplication, and I end up with what we started with in this post.
The word 'the customer' in the 'Given' step above is not much valuable, with that in mind here is my attempt to rewrite the above scenario further.
We pretty much killed the 'Given' step. This is much more brief than having separate scenarios, however can seriously compromise understanding and communication. Consider adding few more similar given steps to the above scenario and the problems will be much more glaring.
Use examples for examples NOT behavior, and don't be deceived by the brevity.
Have you got similar experiences? Have some thoughts/suggestions/comments? Will be delighted to hear.
In my next post I will cover how 'Data vs Information' matters for cucumber scenarios.
P.S.This blog post was updated with Syntax Highlighting for Cucumber to improve readability.
No comments:
Post a Comment