Click here to Skip to main content
Click here to Skip to main content
Go to top

Say Hello To Behavior Driven Development (BDD) - Part 1

, 6 Feb 2011
Rate this:
Please Sign up or sign in to vote.
This article describes the natural evolution of BDD from common problems of developers not following TDD properly. It also describes a bit about Domain Driven Design (DDD) and Domain Specific Language (DSL) which are naturally connected with BDD.

Introduction

This is the first part of a two part series of "Say Hello to Behavior Driven Development". This part is going to introduce you to the concept of Behavior Driven Development.

Part 2 consists of a step by step instruction to build an application following Behavior Driven Development.

A Brief History (or Story) of Almost All Developers

Almost all developers like to code more than they write test code. "Let's write the code first and meet the deadline and if time permits or if I feel OK, then I would write some test code" - is a common mindset of almost each and every developer. Interestingly, they all know the benefits of writing test code. Even a large percentage of them knows the benefits of adopting TDD (Test Driven Development) towards the software development life cycle. But still a very few can adopt TDD and continue with it.

Questions that are Raised in the Mind

The question is why developers feel uncomfortable to write test code? Is there any way to overcome this?

Problem with a Real Life Example

Let's try to find the answers to these questions.

Let's assume that Mr. X is a hardcore .NET developer and he is going to develop a web based email program. His development manager or supervisor or product owner has given the specification of the email program like this.

As a product owner, I would like to get an web based email program by which I can compose email on-line and can send email.

Pretty simple specification!

Now, Mr. X tries to follow TDD and he starts to think what could be the possible test cases.

  1. This program should send email if To address is valid.
  2. This program should send email if CC address is valid even if To address is not valid
  3. This program should send email if BCC address is valid even if CC and To address is not valid.
  4. This program should send email even if the subject line is empty.
  5. This program should send email even if the body is empty.

Now after sorting out these 5 points, he begins to think that there might be some more test cases if the option stated in 1, 2 and 3 are altered. Even there might be more test cases if he considers the format of the body of the email (like plain text, rich text or HTML). If the body is HTML, then he needs to think about the HTML encoding things.

The more Mr. X, the hard core .NET developer gives to think to find possible test cases, the more he finds test cases and one point like all other developers he may write few test cases or not any test cases by keeping in mind that -- "I will definitely write test cases once my functionality has been implemented".

But as usual at the end of the day, almost no test cases have been written and the TDD vanishes!

Let's Find the Cure!

So far, we have got the nature of the problem and its symptoms. Now let's start digging out a possible remedy of it.

What if the requirement given by the product owner or supervisor or development manager included the possible behavior of the module. To elaborate and to be more specific, if the requirement is given in such a way that fully expresses the behavior of the module and its possible corner points, then it would be very easy to decide which test cases need to be written and which are not needed.

Researchers have spent lots of time to figure out a possible format of “requirement specification” that is easy to understand to both technical and non technical person. Experts term this type of language as Ubiquitous Language or Domain Specific Language (DSL). I am not going into details of this thing but as I have already mentioned, the purpose of this is to create a bridge between technical and non technical persons.

Nowadays, the word DDD (Domain Driven Design) is very popular and ubiquitous language or DSL is the first ladder of it. If you are interested to learn more about DDD, then please Google the term DDD and enjoy your ride in DDD world!

You must be wondering why I have brought ubiquitous language or DSL in the middle of solving a complex problem of every developer's life? Fortunately, this Common language type is going to solve our problem. You must be wondering how?

There are some good guys who actually developed such a language that can be written by any person regardless of technical background and that can be read and understood by any people on earth. Interestingly, there are some parsers for this language which can parse this plain English to compilable code of your favorite programming language.

Just one rule needs to be followed, whatever you write, use Given-When-Then steps. Confused? It's really very easy. Even I can write it, and I am writing the above requirements using this guideline.

Given that a web based email module has been developed
And I am accessing it with proper authentication

When I shall write sender email address in To field
Or write sender email address in CC filed by not keeping empty the To field
Or write sender email address in BCC field by not keeping empty either To field
And keeping the subject field non empty
And write something in body text area which excepts rich text
And press or click send button

Then my email will be sent
And the event will be logged in log file.

Isn't it easy to write and read and understand? Doesn't it cover and depict all possible test cases? Hey! Isn't it actually writing a documentation of email module to be developed?

I know the answers of the above three questions are all YES! There is a more exciting thing I would like to share with you, but before going into that, let's concentrate on the above specification to extract some more information that we need to know.

As you can see that along with Given-When-Then steps I have used and/or to bridge different specifications or corner points and you can actually add as many as possible of combinations and/or in order to detail your specification. And still, it is completely readable to any human.

Oh! I forgot to mention the name of this language. It is known as Gherkin. You can visit this link to dig out more information regarding this.

Such type of requirement actually depicts how the module would behave once developed and developer can concentrate more on behaviour rather than writing test cases. Such phenomenon are termed as Behaviour Driven Development (BDD) and I am pretty sure you have understood the basic concept of BDD by now.

There are some tools (free of course) available that can actually parse specification written in Gherkin and can create test cases in your favorite language and isn’t it enough to trigger 'SayWOW' event Wink | ;) .

To implement BDD for .NET, I have found Specflow to be a cool tool that can be integrated with Visual Studio (even it supports VS 2010!). If you Google for more tools, you will definitely find more!

For Java, I have found JBehave to serve the purpose. But again, by Googling, you will get a hell of a lot of tools.

In the second part, I shall show you how you can implement BDD step by step in a .NET project.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mahmudul Haque Azad
Software Developer (Senior) Vizrt Bangladesh
Bangladesh Bangladesh
I am truly versatile and 360 degree Engineer having wide range of development experience in .NET and Java Platform. I am also proficient in system level programming in C++. To me technology is not at all a problem, it’s the client requirement that matters! That is I am ready and comfortable to use any technology to make the business of my client a success.
 
In my five years of experience I have the opportunities to work for fortune 500 companies of US and many renowned clients from Europe.
 
My Linkedin Profile: http://bd.linkedin.com/in/mahmudazad
Follow on   Twitter

Comments and Discussions

 
GeneralRe: My vote of 5 PinmemberMahmudul Haque Azad1-Feb-11 0:16 
GeneralGood one PinmemberShahriar Iqbal Chowdhury31-Jan-11 20:36 
GeneralRe: Good one PinmemberMahmudul Haque Azad1-Feb-11 0:15 
GeneralMy vote of 4 Pinmemberrohitkandhal31-Jan-11 19:13 
GeneralRe: My vote of 4 PinmemberMahmudul Haque Azad1-Feb-11 0:14 
GeneralMy vote of 5 PinmvpAl-Farooque Shubho31-Jan-11 17:33 
GeneralRe: My vote of 5 PinmemberMahmudul Haque Azad1-Feb-11 0:10 
GeneralMy vote of 5 PinmemberHassanur29-Jan-11 5:22 
GeneralRe: My vote of 5 PinmemberMahmudul Haque Azad1-Feb-11 0:09 
Generalmy vote of 5 PinmemberMaximus Byamukama28-Jan-11 6:41 
GeneralRe: my vote of 5 PinmemberMahmudul Haque Azad29-Jan-11 3:11 
GeneralOld stuff - new name PinmemberLugnuts28-Jan-11 5:29 
GeneralRe: Old stuff - new name PinmemberMahmudul Haque Azad29-Jan-11 3:08 
GeneralRe: Old stuff - new name PinmemberSuchi Banerjee, Pune11-Feb-11 13:47 
GeneralGood article PinmemberCIDev21-Jan-11 2:17 
GeneralRe: Good article PinmemberMahmudul Haque Azad21-Jan-11 5:49 
GeneralRe: Good article PinmemberCIDev11-Feb-11 9:04 
GeneralMy vote of 5 Pinmvpdefwebserver20-Jan-11 6:21 
GeneralRe: My vote of 5 PinmemberMahmudul Haque Azad20-Jan-11 15:36 
GeneralLinks PinmvpHenry Minute20-Jan-11 3:55 
GeneralRe: Links PinmemberMahmudul Haque Azad20-Jan-11 15:36 
GeneralMy vote of 5 Pinmemberkdgupta8719-Jan-11 19:12 
GeneralRe: My vote of 5 PinmemberMahmudul Haque Azad20-Jan-11 15:36 
GeneralMy vote of 5 PinmemberGPUToaster19-Jan-11 19:08 
GeneralRe: My vote of 5 PinmemberMahmudul Haque Azad20-Jan-11 15:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 6 Feb 2011
Article Copyright 2011 by Mahmudul Haque Azad
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid