Archive for the ‘BDD’ Category

developwithpassion.bdd – notes

30 April, 2009 1 comment

A few notes I’ve compiled while starting to play with JP Boodhoo’s BDD framework ( At first sight the syntax looks quite alien but try it for a while you eyes soon adjust.

JP blog posts

Base classes

  • observations_for_a_static_sut – For testing a static class or a quick inline test
  • observations_for_a_sut_with_a_contract – For testing against the interface of a class
    • sut is automatically created
    • No more broken test when you add a new dependency to a class! YAY
    • Automatic creation of sut can be over ridden
  • observations_for_a_sut_without_a_contract – For testing against a concrete class

Delegate call order

  • context
    • Can define a context block in the concerns base class which will be run before a context block in the inheriting class
    • Can call method provide_a_basic_sut_constructor_argument
  • after_sut_has_been_initialized
  • because
  • it
  • after_each_observation


When you want to test spec? for an exception use the doing method:

because b = () =>
    doing(() => sut.MethodWhichThrows());

it should_throw_exception = () =>
    exception_thrown_by_the_sut.Message.should_contain("MY EXCEPTION");

Categories: BDD Tags:

Books + Head First C# + Lab 1 Solution

3 January, 2008 4 comments

I’ve been reading through the new Head First book Head First C#
which appeared on Safari just before Christmas. I’ve been a fan of the Head Fist books ever since reading their best selling Head First Design Patterns book. This particular book is aimed at beginners / hobbyists so I’m not exactly the target audience but hey it covers C# 3 so its got to be worth at least a skim.

I was pleased to see they’ve added a new feature to the head first series namely lab sections. There are 3 lab sections in the book which are basically specifications for mini games, the idea being the reader creates the games using their newly acquired C# skills. I though this was a great idea and having a lot of spare time in front of my laptop over the Christmas (due to a very sore ankle) I did the first of the labs “A day at the races”.

I used the lab as an exercise in Behaviour Driven Development (BDD) which I’d recently read about here and here. I also got to try out a Test Data Builder I’d read about here. Now I’m not convinced I hit the nail on the head with the BDD as my solution wasn’t created in a test behaviour first manor. This was mainly due to the fact the book provides you with the shell of a solution to keep things nice and simple for beginners. Never the less it was a good fun doing the lab it’s a great way to try out new techniques.

All in all the BDD experience was pretty good not sure about the code duplication in the context setup but you got to love the way the descriptive contexts and method names combine to read like a sentence:

Also the Test Data Builder is a really flexible way to create test data using a fluent interface which again is really easy to read:

myGuy = new GuyBuilder().WithName("Joe").AndCash(50).Build();

You can download the solution here.

Categories: BDD, Books Tags: ,