Thoughts on Technology, Methodology and Programming.

Behavior Driven Development

Posted by Marcus Wyatt on 1 October 2005

After reading Dave Astels post on Behavior Driven Development called “A New Look at Test Driven Development”and having a listen to his podcast on Behavior Driven Development that he did at Agile 2005 with the “Agile Toolkit Podcast” team, I started to become more curious…

So I got my “Test-Driven Development in Microsoft.NET” book and the chapter 2 example looked like a good example for my first attempt at BDD. I selected the Unbounded Stack Test list and thought about what I’ll name the test method that I’ll use when I am writing test to implement the requirements.

Here is the list of tests and test method names:

  • Create a Stack and verify that IsEmpty is true. = New_Stack_Should_Be_Empty
  • Push a single object on the Stack and verify that IsEmpty is true. = Push_Object_Stack_Should_Not_Be_Empty
  • Push a single object, Pop the object, and verify that IsEmpty is true. = Push_Pop_Object_Stack_Should_Be_Empty
  • Push a single object, remembering what it is, Pop the object, and verify that the two objects are equal. = Push_Pop_Object_Should_Be_Same
  • Push three objects, remembering what they are; Pop each one, and verify that they are removed in the correct order. = Push_Pop_Multi_Object_Should_Be_Same
  • Pop a Stack that has no elements. = Pop_Empty_Stack_Should_Throw_Exception
  • Push a single object and than call Top. Verify that IsEmpty is false. = Push_Top_Stack_Should_Not_Be_Empty
  • Push a single object, remembering what it is; and than call Top. Verify that the object that is returned is the same as the one that was pushed. = Push_Top_Object_Should_Be_Same
  • Call Top on a Stack with no elements. = Top_Empty_Stack_Should_Throw_Exception

Now if we have a look at the source code for the first two tests the intent becomes as clear as daylight:

public void New_Stack_Should_Be_Empty()
public void Push_Object_Stack_Should_Not_Be_Empty()
   stack.Push("first element");
   Assert.IsFalse(stack.IsEmpty, "After Push, IsEmpty should be false");

I know Dave is working on a new framework for BDD, but I think that in the mean time I’ll start writing my TDD test using method names that is more BDD. This does help with making the intent of the test a lot clearer.

tags: , ,

Currently listening to: wer mix) – Winamp *** 11. Balearic Bill – Destination Sunshine (DJ Tiësto Power mix)


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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: