Two flavours of BDD – or .net gets behaviour-driven

How about that? You wait ages for a BDD framework in .net and then two come along at once! Ok, to be fair NSpec has been around for a while. However I’m talking about describing application behaviour in terms of stories and scenarios, to complement NSpec’s description of interactions between objects. (As a side note, I would love to see NSpec adopt rspec’s describe/it vocabulary rather than using contexts and specifications.)

Introducing NBehave and, well, NBehave!

Morgan Persson first spoke to me about writing a .net version of JBehave at the beginning of 20071, so I am delighted that he has just announced his first public release of NBehave. It mixes C# and VB.net in a lovely it’s-all-about-the-CLR way. So the examples are in C#, extending VB.net framework classes.

In the meantime, Joe Ocampo has used some C#3 voodoo to create something scarily similar to rbehave for .net. He seemed to produce this in slightly less time than it took me to press “publish” in WordPress, and I have to say it looks great.

Two use cases for expressing intent

The original idea behind the JBehave story framework was that developers would write “pluggable” givens, events and outcomes to define the various scenarios that make up each story. Non-technical people would then manipulate these using desktop tools (say a graphical story builder where you drag the various components around to define your stories and scenarios).

rbehave has a different motivation, namely moving from the textual representation of a story to an executable definition in as few steps as possible. This is to allow human beings – mainly testers and business analysts – to read, write and edit executable acceptance criteria.

Liz Keogh and I are currently preparing a JBehave tutorial for OOPSLA 2007. Since JBehave was based very much on the first use case, we’ve noticed it is pretty painful to pull together a story from a standing start, without a proliferation of tiny classes emerging. I’m working on a fluent interface that is currently looking a little like this:

public Story story() {
    return newStory("I can create a cell")
        .asA("game producer")
        .iWant("to create a cell")
        .soThat("I can show the grid to people")
    .withScenarios(
        scenario("Nothing to see here",
            given("a game with dimensions", 3, 3),
            then("the grid should look like",
                    "...",
                    "...",
                    "...")
        )
    );
}

It’s backed by the regular JBehave classes and runs in the standard JBehave story runner.

I would love to see Morgan and Joe bring their two interpretations of acceptance-level BDD together into a single framework. It is after all just a bunch of scenario fragments playing nice together, and having the two approaches to expressing intent in the same framework means that NBehave could be both a directly-editable representation of behaviour, and at the same time the basis of a (graphical?) toolset for defining acceptance criteria in .net. Maybe even as a Visual Studio plugin.

1. Oops – I thought it was as long ago as 2006 but Morgan put me straight.

6 comments

  1. Thanks Dan!

    I agree that I should get with Morgan to see if we can create one framework (If the community accepts my approach) because frankly I am confusing myself with every new BDD framework that is being created. Simplicity and consolidation are the way to go.

    On a side note I updated my post with the latest changes. Not bad but I wanted to make sure I stayed true to your vision of rbehave. Let me know what you think.

    http://www.agilejoe.com/archive/2007/06/28/introducing-nunit-behave-or-insert-what-ever-other-catchy-name.aspx

  2. […] Two flavours of BDD – or .net gets behaviour-driven- BDD for .NET, baby. […]

  3. Good post. You make some great points that most people do not fully understand.

    “rbehave has a different motivation, namely moving from the textual representation of a story to an executable definition in as few steps as possible. This is to allow human beings – mainly testers and business analysts – to read, write and edit executable acceptance criteria.”

    I like how you explained that. Very helpful. Thanks.

  4. Hey Dan!

    Just wanted to let you know that we\’re about to release Stormwind.Accuracy release 0.4.0 with a lot of new goodies.

    You can find more about Accuracy in http://using.stormwindproject.org:8081/display/accuracy/Home.

    It\’s a BDD-style Acceptance Test framework for Web Apps. It\’s entirely written in .Net and it uses WatiN as a browser Driver. We have a ticket for implementing support for Selenium, but so far noone ventured in that area.

    You can also check the roadmap ahead for Accuracy in http://jira.stormwindproject.org.

    We have 2 thoughtworkers working in Accuracy as of now and several different devs from all over the world as well.

    It\’s growing to be very useful!

    Anyway, just thought of mentinoning!

    Bernardo Heynemann
    Dev @ ThoughtWorks UK

Follow

Get every new post delivered to your Inbox.

Join 485 other followers

%d bloggers like this: