Archive

Archive for January, 2009

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

    First training course of the year

    January 16th, 2009

    borough market

    Last week I taught my first course of the year for Concentra. I have heard some horror stories about running internal training courses but I really enjoyed it. It’s definetly a cool place to work, there’s some smart people there.

    I used an evolutionary teaching style where we started writing raw C# code without LINQ and moved towards third party libraries like log4net, NHibernate and ASP.Net MVC. There was just too much to cover and really It should’ve been the original 5 day course I had planned.

    I find that teaching really makes you need to know what your talking about. Most of the time you are not writing infrastructure code and to be able to start an app from scratch lets you reassess how you do things.  I have a big crush on Iteration 0 efficiency there’s so much to setup and if you start into app code prematurely you end up working with a handicap.

    Here’s the outline of what we managed to cover, I will be posting code shortly.

    Day 1

    • Refactoring
    • TDD
    • BDD
    • Team System
    • IComparer<T>
    • Paired Programming
    • Delegates
    • Predicate<T>
    • Specification Pattern
    • Strategy Pattern
    • Lambdas
    • Searching and Sorting on Collections
    • Fluent APIs
    • Rich Domain Model
    • Barebones Data Access

    Day 2

    • Refactoring Data Access
    • Factory Pattern
    • DBProviderFactory
    • log4net
    • Service Layer Pattern
    • Mapper Pattern
    • Repository Pattern
    • NHibernate
    • Detached Criteria

    Day 3

    • ASP.Net MVC
    • JQuery
    • AJAX calls with JQuery
    • Scrum
    • User Stories
    • Kanban
    • Dependency Injection
    • Rhino Mocks

    Uncategorized