Getting started with Boodhoo BDD
Boodhoo BDD is a set of libraries that abstracts Rhino Mocks and MBUnit to give you an easy way to write BDD Specifications (a readable form of unit tests).
I’ve been using JP Boodhoo’s BDD helper libraries on a few projects and I’ve seen my tests become documentation because they’re more readable. I’ve been using it to set up our development team with application modules in a design by contract methodology. Which means that tests are in place first to provide a high level contract of the inputs and outputs of the class.
I’ll be covering this again in a grok talk tonight at the LDNUG but consider this a thorough transcript.
Definitions
- Here’s all the components you need to start developing using Boodhoo BDD.
jpboodhoo.bdd
helper libraries which give you a fluent interface to rhino mocks and mbunit so your interaction with these frameworks are abstracted away and readable.
you’ll need the following references to take full advantage of all the extension methods and reporting functionality of bdd doc.
jpboodhoo.bdd.dll jpboodhoo.commons.core.infrastructure.dll bdddoc.core.dll
checkout the latest version from http://subversion.assembla.com/svn/jpboodhoo_bdd with a subversion client like tortoisesvn
or you can download a build from here
here’s all the using statements you’ll need
using bdddoc.core; using jpboodhoo.bdd; using jpboodhoo.bdd.concerns; using jpboodhoo.bdd.contexts; using jpboodhoo.bdd.core;
first we need to setup all the concerns for our movie repository, this is where we would setup and dependancies and override the MovieRepository constructor if is need to inject anything.
public abstract class concern_for_movie_repository : observations_for_a_sut_with_a_contract
{
}
and the specification looks like this
[Concern(typeof (MovieRepository))]
public class when_all_movies_are_asked_for : concern_for_movie_repository
{
static IEnumerable results;
static concern c = () => {};
static because b = () => results = sut.All();
[Observation]
public void should_find_a_movie()
{
results.Count().should_not_be_equal_to(0);
}
}
the main points are
- Concern is a MBUnit TestFixture
- Observation is a MBUnit Test
- sut is a MovieRepository which is created in observations_for_a_sut_with_a_contract based on the Generic type.
- concern,because and any fields need to be static
- a concern in concern_for_movie_repository will run before the concern in when_all_movies_are_asked_for
Here’s some more thorough examples to get you started
AutoHotKey BDD naming
A script for AutoHotKey which replaces the spaces you type with underscores so you can quickly describe your behaviours in a underscore naming convention. You use Ctrl-Shift U to turn this off and on and there’s a tray icon to tell you if its on or off.
After you download the
BDD Doc
BDD Doc is the report generator of this package. It uses the Concern and Observation attributes that we used above and generates an html report to show you which Concerns are behaviours of which Objects.
If you have an MBunit test report you can include the results in the BDD Doc report too.
you can checkout bdd doc here with a subversion client
http://svn2.assembla.com/svn/bdddoc
Here’s how you call BDD Doc at command line.
bdddoc.console.exe tests.dll TestAttribute SpecReport.html test.report.xml
and here’s what the SpecReport.html report will look like

Resharper Templates
File Templates are Live Templates allow you to insert new files and do code insertion with aliases. Its not needed but its definitely useful for developing faster.
you can import the live templates by going to Resharper > Live Templates and clicking on the import button below.

Welcome to a world with readable code.
Great post Scott. Thanks for all the help you gave in Las Vegas last year.
FWIW context/because shouldn’t need to be static, but the fields do so that they can be referenced within the lambdas.
you’re right, looking one of my current projects I wasn’t even using statics on the context/because.
for anyone else who’s looking, JP’s source code has moved. See http://blog.jpboodhoo.com/DevelopWithPassionGitHub.aspx