Using BDD Tools To Write Automated Checks != BDD

Using Cucumber, SpecFlow or similar tools to write your automated checks, is not doing BDD. Cucumber, SpecFlow or similar tools are not testing tools ¹. I believe they were designed to facilitate the process of BDD. Sure they could be accompanied by other tools and code to form a testing tool, but as this post will elaborate on, its important to understand what doing that means.

I am seeing a surge, well it was a surge at first, it's considered the norm now, I gauge this by using blog posts I see, message forums and job adverts. I probably first noticed it in 2013. This surge is people using tools that have come out of the BDD community for their automated checks, with the most popular being Cucumber and SpecFlow.

Is there a problem? Maybe, as always it depends on the context. But what I do have a problem with is people claiming that by doing this, they are indeed doing BDD. Now I should make it clear from the off, I am no BDD expert, I have a shallow understanding of it, read a few books, a few blog posts, never worked anywhere claiming to do BDD, however I have worked in companies were collaboration is strongly encouraged, if not mandatory, and my understanding of BDD is that it's routed in increasing collaboration. Does writing your automated checks in SpecFlow/Cucumber increase collaboration? Minimally if at all.

My next gripe is people using Cucumber/SpecFlow in their automated checks, well, just because! "Why wouldn't we", I hear them cry, shortly followed by "it makes everything readable". It could make it more readable, however sadly the way most implement (generalisation here), but also based on what I read about and have experienced, they don't write them in a readable way. Ok I should make this more clear, the "steps" may be very readable, but what the scenario is checking, not so much. But thats the point of writing scenarios in gherkin, right?

There is a great example of that in, Fifty Quick Ideas To Improve Your Tests by Gojko, David and Tom in the chapter titled "Use Given-When-Then in a strict sequence". It reads like this.
Given the admin page is open
When the user types John into the 'employee name'
and the user types 30000 into the 'salary'
and the user clicks "Add'
Then the page reloads
And the user types Mike into the 'employee name'
And the user types 40000 into the 'salary'
And the user clicks 'Add'
When the user selects 'Payslips'
And the user selects employee number 1
Then the user clicks on 'View'
When the user selects 'Info'
Then the 'salary' shows 29000
Then the user clicks 'Edit'
and the user types 40000 into the 'salary'
When the user clicks on 'View'
and the 'salary' shows 31000
Have you seen a scenario like this before? What is this scenario actually checking? It's not immediately obvious to me, you? I am not going to dive into detail of what it could be, based on the above, as the author of the chapter has already done a great job of that, so I recommend reading it. But a possible scenario could read as
Given an employee has a salary 'X'
When the tax deduction is 'Y'
Then the employee gets a payslip
and the payslip shows 'Z'
Which works better for you? The latter I would hope. It's clear what the scenario is doing. Its clean. Also in most cases where BDD may be being practiced, or the acceptance criteria is being written in gherkin, it's directly related to the story, and could subsequently serve as an education resource for someone wanting an insight into some features/behaviours. The same couldn't be said for the first example.

So why are so many people automating like the first example, where we don't have these advantages?

I have started calling the first example TestCase 2.0 - By this I mean, if the steps are written like such, someone without any technical skills, can come along and make some new scenarios, just by plugging some steps together. They never have to look at the plumbing underneath, it remains hidden. It's like feature files have replaced spreadsheets... step driven automation instead of keyword driven automation. Takes little thought, and subsequently returns little value.

It's understandable why someone would use it this way if such a framework existed, "what! I can just search for steps and create 100s of new scenarios, awesome!" Sadly it's not. Not going to dive into that in this post, but we need automation that supports us, creating scenarios for the sake of it, especially ones where the scenario isn't clear, in the long run, isn't going to help anyone. Also, the more you add, the longer you wait for your feedback, you know the fast feedback that automation could provide.

I am not saying don't use tools such as Cucumber/SpecFlow in your automated checks, but think about why you would.
  1. What's the advantage?
  2. Where's the value coming from? 
  3. Who is your target audience for reading your scenarios?
But be clear to yourself and your team with what it is you are doing. In most cases you are using BDD tools as part of your automation framework, not doing BDD, so don't fool yourself or others into thinking you are.

So do use Cucumber/SpecFlow, but use it for the right reasons, use it to make it clear to you and other what the scenario is checking. Not because it's the "cool" tool at the moment.

If you still think what you are doing is BDD, then I have listed some references at the bottom.

References

¹ https://cucumber.pro/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool.html
https://cucumber.io/blog/2015/06/18/hamish-tedeschi-what-is-bdd
https://cucumber.io/blog/2015/07/13/anne-marie-cukeup-question-and-answer
http://prezi.com/hhmqznflya0l/?utm_campaign=share&utm_medium=copy&rc=ex0share

Look up Dan North & Liz Keogh's work on BDD.


3 comments:

  1. You've pretty much summed up why I've avoided BDD-specific tools like the plague. You can write clear, well structured checks in any language.

    This is a conversation I've had with a developer not too long ago:
    Him: So we used tool X to do BDD in a previous project.
    Me: Why? Was it useful?
    Him: Well yeah, kind of. You could write a new test even if you couldn't code.
    Me: Weren't the developers writing these tests?
    Him: Well yeah. But it allowed non-technical people to read the tests and understand them.
    Me: Who were these non-technical people that were reading your tests?
    Him: Well the Product Owner could easily read the test scenarios if they wanted to.
    Me: Did they ever read them?
    Him: I don't know.
    * At this point I turn to a Product Owner who was sitting right next to me
    Me: Would you read our automated checks if they were easier to understand? Would they bring you any value?
    PO: No! Why would I do that? I trust you guys to do this stuff. I don't care as long as the feature is delivered. I'm busy enough as it is.

    Needless to say I wasn't convinced. :)

    ReplyDelete
  2. That's why, while I am a big fan of Cucumber, I think there needs to be a lot more education around what it makes sense for. Most of the time I see teams use it, they really should just be using RSpec or some variation on it (RSpec-Given perhaps).

    ReplyDelete
  3. Couldn't agree more with the article, I've written about this very subject over here

    https://github.com/xolvio/automated-testing-best-practices/blob/master/content/TESTING-SUCCESS-FACTORS.md#lesson-2-say-no-to-natural-language-test-scripts

    BDD is very misunderstood, and it's because it requires a bit of a paradigm shift to be done properly. Education is definitely the right approach to so thank you for writing this.

    Sam

    ReplyDelete