How to Debug Fitnesse Fixtures

I was recently discussing the advantages and disadvantages of Fitnesse with a colleague and he mentioned that one of the biggest drawbacks is that you can’t debug fixtures.  I have managed to debug fixtures using the technique I’m going to outline here.  I haven’t actually seen this technique mentioned anywhere so if you are aware of a better way of doing this please let me know using the comment section below.

A typical example

Let’s take a look at a typical fixture and how we would go about to setup debugging.  I have create a simple calculator class for this example.

public class CalculatorFixture : ColumnFixture
{
    public decimal Arg1 { get; set; }
    public decimal Arg2 { get; set; }

    public decimal Add()
    {
        return new Calculator().Add(Arg1, Arg2);
    }

    public decimal Minus()
    {
        return new Calculator().Minus(Arg1, Arg2);
    }
}

Here is what happens when I run these fixtures.

ErrorOnMinusFixture

It seems there is an error with our minus implementation.

Debug it!

There are 2 easy steps to debug this fixture.  Firstly, add the following line of code to the start of the Minus method in our fixture.

Debugger.Launch();

Now when you run your fixture you should see the Visual Studio JIT Debugger window.  Simply select your current instance of Visual Studio.  Now you should get a breakpoint inside your code.

DebuggerAttached

And you can debug to your heart’s content.

Happy coding.