BDD for dummies

Aline Paulucci
2 min readSep 20, 2017

--

It was very funny when I created my very first study in Behavior Driven Development (BDD) using SpecFlow. The feature file was created and I read the following on its contents: “In order to avoid silly mistakes / As a math idiot / I want to be told the sum of two numbers”. They weren’t telling me that I was an idiot, but that word bothered me. “I am not an idiot!” (specially regarding math — I really love maths and fisics). And then it was a fight between the superego and “well, I am starting to study, so yeah, I am a BDD idiot”… lol… And I remembered those books “for dummies”.

Leaving my superego aside, after I overcame that, I created a simple example to test BDD aproach: a supermarket list.

As I said, I used the SpecFlow tool in Visual Studio 2015, and NUnit tool for the tests. Here are the steps:

1 — Create a Class Library

2 — Add nuget packages: SpecFlow, NUnit, NUnitTestAdapter

3 — Add a new Feature File. Those are the files where you will write the scenarios, in english (or another language you choose), as follows:

4 — Define the steps. In other words, translate english to c#.

5 — Write your code

So, you write your code, and test it, according to the functionality’s behavior. One more behavior, more code.

Speaking a little bit more about BDD, the process came up to share the understanding between business people/stakeholders of the project and the technical team, before development work starts. This language is called ubiquitous language, and is a (semi-)formal language that is shared by all members of a software development team — both software developers and non-technical personnel.

BDD is a second-generation, outside-in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.” said Dan North during the “Agile specifications, BDD and Testing eXchange” in 2009.

The BDD envolves Context (Given / The starting state), Event (When / What the user does) and Outcomes (Then / The expected results). This format/structure is called Gherkin.

I added more scenarios to this demo project, and you can find it at my GitHub Account.

After feeding my ego, I upgraded from IDIOT to BEGINNER. Woww… 💪🏻💪🏻 Such a difference… I hope I helped you change your BDD status too. Always learning, folks!

Reference: Behavion Driven Development — Wikipedia

--

--