A few notes I’ve compiled while starting to play with JP Boodhoo’s BDD framework (http://github.com/developwithpassion). At first sight the syntax looks quite alien but try it for a while you eyes soon adjust.
JP blog posts
- How I’m Currently Writing My BDD Style Tests – Part 1
- How I’m Currently Writing My BDD Style Tests – Part 2
- Test examples with MBUnit and jpboodhoo.bdd
- Slight addition to jpboodhoo.bdd
- Using jpboodhoo.bdd with TestDriven.Net
- More new conventions for how I organize my tests!!
- 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
- 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
When you want to
test spec? for an exception use the doing method:
because b = () =>
doing(() => sut.MethodWhichThrows());
it should_throw_exception = () =>
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.