Behavior Driven Design and Specificity

I’ve been using an assertion framework at least similar to the one I’ve put up on CodePlex called Specificity for quite some time now. The main goal of that library is solely to provide an assertion framework that’s extendable and discoverable, and it does so in a fashion that doesn’t tie it to any specific test framework. The naming conventions used within Specificity follow a more of the BDD form rather than the TDD form, with Should instead of Assert. However, I’ve not actually used any of the BDD frameworks available for .NET, mostly because I have to use MsTest at work and I am accustomed to using it and so continue to use it outside of work. Recently, I’ve been experimenting with following BDD at least to the extent that my unit testing framework of choice will allow (the Test terminology leaks through in the attribute names used, which BDD purists would not care for). This has eventually lead to me experimenting with a base class that I think may be useful for inclusion in Specificity. This base class isn’t tied to any testing framework, and thus could be a drop-in base class for tests you write using any existing testing framework, much like the assertions in Specificity. The base class is really quite simple, though I’m sure it could be expanded. Part of the inspiration came from Jean-Paul S. Boodhoo, though I’ve simplified it quite a bit in ways that most developers would be more comfortable with, I think. Here it is in all its glory (such as it is):

public abstract class Observations<TResult>
    private bool acted;
    private TResult result;

    protected TResult Result
            if (!this.acted)

            return this.result;

    protected virtual void Arrange()

    protected abstract TResult Act();

    private void ArrangeAndAct()
        this.result = Act();
        this.acted = true;

That’s it. I told you there wasn’t much to it. I’ve chosen to follow the AAA (Arrange, Act and Assert) terminology rather than the “context” and “because” terminology used by Jean-Paul, but the examples from the blog post of his that I linked are easily translated. Here’s his first example, just to give you the flavor of how this is used.

public class When_adding_2_numbers : Observations<int>
    protected override int Act()
        return 2 + 2;

    public void should_result_in_the_sum_of_the_2_numbers()

Of course, this was in MsTest, but you should be able to easily translate it to whatever test framework you use. I’ve not leveraged the Setup concepts available from most testing frameworks because it would tie the code to a specific testing framework, and because some frameworks (looking at you, don’t have the concept, relying on the constructor instead. I’ve not addressed cleanup here, though it should be possible to work that one out. If your test methods are side effect free (they should be), there’s little purpose in enabling cleanup, so I’ve not bothered to think to deeply on that one.

This seems extremely simplistic, but the point behind the base class is to force a BDD approach to testing, where you have a test per feature, rather than a test per class. It’s a poor man’s addition to a TDD framework to enable a BDD style.

I’d love to hear input on this one. What do people think of the idea? What about the implementation? Should something like this go into Specificity? Nit-pick me to death, please.

Related: Behavior Driven Design and Specificity – Part II


  • Daren Smith said

    I was just wondering about the tutorial which delivers the result of designing techniques and behavior, these testing frameworks are quite interesting but quite difficult to understand the whole concepts.

  • not fake said

    To know more details about loan quotes related to such kind of fiscal aid, you are going to ought to search from your internet not fake in general, people borrow this deal to obtain gone urgent issues
    including wellbeing, grocery, water supply, car title fast
    cash loan , school fees and in many cases other issues as well.

  • Cheap Miami Hotels Great Deals in Value said

    Hello, i believe that i saw you visited my web site thus i got here to go back the prefer?.I am trying
    to find issues to enhance my site!I suppose its
    adequate to use a few of your concepts!!

  • voyance immediate said

    It's really a cool and helpful piece of information.
    I am glad that you just shared this useful information with us.

    Please keep us up to date like this. Thanks for sharing.

  • said

    Wow! In the end I got a web site from where I know how
    to actually obtain useful information regarding my study and knowledge.

  • Eusebia said

    Good day! This is kind of off topic but I need some guidance from an established blog.
    Is it tough to set up your own blog? I'm not very techincal
    but I can figure things out pretty quick. I'm thinking about creating my own but I'm
    not sure where to start. Do you have any points or suggestions?

  • Surfthechannel said

    Heya i am for the primary time here. I came
    across this board and I in finding It really helpful & it helped me out a lot.

    I'm hoping to offer something back and aid others
    such as you aided me.

  • reno auto injury attorney said

    It's really very difficult in this active life to listen news on Television, therefore I only
    use web for that purpose, and take the most recent information.

  • Http://Www.Youtube.Com said

    Hi I am so excited I found your blog page, I
    really found you by accident, while I was looking on Askjeeve for something else, Anyhow
    I am here now and would just like to say thanks a lot for a remarkable post and a all round exciting blog (I also love
    the theme/design), I don’t have time to read it all at the minute but
    I have saved it and also added your RSS feeds, so when I have time I
    will be back to read a lot more, Please do keep up the awesome jo.

  • said

    You actually make it appear so easy along with your presentation but I in finding this topic to be actually something
    that I think I'd by no means understand. It sort of feels too complicated and extremely huge for me.
    I'm looking forward to your next put up, I'll attempt to
    get the grasp of it!

  • Klaudia said

    My programmer is trying to persuade me to move to .net from PHP.

    I have always disliked the idea because of the expenses.

    But he's tryiong none the less. I've been using Movable-type on various websites for about
    a year and am nervous about switching to another platform.
    I have heard fantastic things about Is there a way I can import
    all my wordpress posts into it? Any kind of help would be really appreciated!

Add a Comment