Behaviour Driven Development

Monday, February 6th, 2006

A few days back, I was listening to Dave Astels talk on Behaviour Driven Development on the Agile Toolkit Podcast. It struck a chord!

As a brief overview, Behaviour Driven Development (BDD) derives from Dave Astels experience with Test Driven Development (TDD). In TDD you write your tests before you write your code. Dave argues that this has been misunderstood (see A new look at TDD) and that TDD isn’t about testing the code but about specifying its behaviour. He suggests that changing the vocabulary might improve the quality of TDD, and coins BDD as a way forward.

This resonates with my experience so well! How many times have I seen developers misusing unit tests. Here is an example of what I mean: there is an idiom in Java that says one unit test class per class in the system, and one test method per method in the tested class (Eclipse’s “JUnit test case” wizard does that – note that I am not trying to bash Eclipse here!). This has to be one of the main culprits for the bad usage of JUnit. A TestCase should be about one case, not all use cases! So there should be multiple test cases per class to test. With BDD, the shift in vocabulary tends to force the developer to split the test case in multiple specifications contexts. The tests are not expressed in terms of assertions (prefixed with assert) but in terms of duty (prefixed with should). This helps reinforce the purpose of writing tests first.

Some might say that BDD is only a thin layer on top of TDD. This might be true but I think it is missing the point. BDD is not a paradigm shift, it is an evolution of TDD based on experience. BDD is a pragmatic refactoring of TDD.

I would recommend having a look at RSpec, Dave’s BDD framework in Ruby.


2 Responses to “Behaviour Driven Development”

  1. Good one – test case per usecase and not class.

  2. […] Back in February, I told you about Behaviour Driven Development using RSpec. Things have moved in very interesting directions since then. […]

Comments are closed.

%d bloggers like this: