Behavior-Driven Development

November 23, 2007

I’ve started looking at Behavior-Driven Development (BDD) and more specifically RSpec for Ruby. BDD is an evolution of Test-Driven Development (TDD) which aims to make developers look at it from another perspective and not regard it as testing in a sense. So it’s more of a new way of expressing your intent rather than an entirely new approach to tests (or specs as the BDD community calls it).

You divide your code into small pieces of behavior, rather than the more abstract term units and write what it should do.

Here are two examples of the difference:

NUnit (C#) RSpec
Assert.AreEqual(expected, actual) actual.should equal expected
Assert.IsTrue(bool) Bool.should be_true

Edit: I tried pasting some code I’d written here, but the wordpress editor sucks when it comes to formatting code. But you can find great examples here and here.

I just watched a video where Dave Astels (one of the guys behind RSpec) explains why you should take a look at BDD if you’re into TDD. To quote him: “Behaviour Driven Development is what you were doing already if you were doing Test Driven Development very well”. You can also read his PDF A new look at test-driven development (8 pages) where he explains his views and why too few people “really understand what it’s really about. That means that many people who practice TDD are not getting the full benefit from it”.

2 Responses to “Behavior-Driven Development”

  1. ActiveEngine Sensei Says:

    Here is a link to a post concerning a C# class that will allow you to introduce NBehave like functionality to NUnit. Take a look:

    http://www.lostechies.com/blogs/joe_ocampo/archive/2007/06/28/introducing-nunit-behave-or-insert-what-ever-other-catchy-name.aspx

  2. Piku Says:

    The new RSpec 1.1 also comes with Story Framework which makes it easy to write specs.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: