Behaviour Driven Development using Specflow with Webdriver and Nunit – Part 1

What is Behaviour Driven Development ?

In this 3 part series of blogs, I will talk about behaviour driven development within a .Net agile project using Specflow, Webdriver and NUnit  going through the set up of Specflow and Webdriver and its benefits.

Test-driven development on agile projects involves development teams first writing a test for each function and then getting the code to work for that. The problem with this approach has been that it becomes too much development orientated. Behavior-driven development however on the other hand is based on the user and how they want the application to behave.

Instead of writing tests you should think of specifying behavior. Behavior is how the user wants the application to behave.

When your development is Behavior-driven, you always start with the piece of functionality that’s most important to your user. I consider this phase as taking the developer hat off and putting the user hat on. Once you’ve specified the user needs, you put the developer hat back on and implement your specification.

In my experience, this is the hardest part of the process: Often you don’t know what’s the most important behavior for your user. However, over time and with a lot of feedback it becomes more apparent. But we’ll get into that in a later blog post.

In behavior-driven development you specify behavior that the customer wants in a way that is in the format of executable tests. The naming should be easy to understand and the wording should also be easy to read and make sense of.

Your project members or indeed even the customer will not have to read a single line of code.

When you run all these specifications, these form your regression pack. When a regression test fails, you immediately see what behavior of your application is broken.

Each story has a title and a short description of what the story is about. The format of this description is always the same:

As a <type of user>,

I want <some goal>,

So that <some reason>

This description is always followed by a list BDD tests in Gherkin syntax containing Given steps (sequential steps), When steps (trigger) and Then steps (the expected outcome).

You can use a browser automation library like Selenium Webdriver,  and script it either using a framework like Cucumber (for Ruby) or SpecFlow (for .NET).  We will focus on Specflow in a .NET environment.