Home > Uncategorized > Getting started with Boodhoo BDD

Getting started with Boodhoo BDD

January 28th, 2009

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

  1. BDD – Behaviour Driven Development
  2. AAA – Arrange-Act-Assert syntax testing
    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

  1. Concern is a MBUnit TestFixture
  2. Observation is a MBUnit Test
  3. sut is a MovieRepository which is created in observations_for_a_sut_with_a_contract based on the Generic type.
  4. concern,because and any fields need to be static
  5. 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

  • Test examples with MBUnit and jpboodhoo.bdd
  • How I’m Currently Writing My BDD Style Tests – Part 1
  • How I’m Currently Writing My BDD Style Tests – Part 2

    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

    or download a build here

    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

    bdddoc_report

    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.

    download live templates

    you can import the live templates by going to Resharper > Live Templates and clicking on the import button below.

    bdd-livetemplates01

    Welcome to a world with readable code.

  • Uncategorized

    1. Chris Mitchell
      January 28th, 2009 at 21:54 | #1

      Great post Scott. Thanks for all the help you gave in Las Vegas last year.

    2. February 12th, 2009 at 06:40 | #2

      FWIW context/because shouldn’t need to be static, but the fields do so that they can be referenced within the lambdas.

    3. February 12th, 2009 at 11:15 | #3

      you’re right, looking one of my current projects I wasn’t even using statics on the context/because.

    4. Justin Thirkell
      May 5th, 2009 at 03:25 | #4

      for anyone else who’s looking, JP’s source code has moved. See http://blog.jpboodhoo.com/DevelopWithPassionGitHub.aspx

    1. No trackbacks yet.