Friday, January 6, 2012

How to debug FitNesse .NET in Visual Studio - FitNesse improvements Part 1

This is the first of a three part series where I introduce to FitNesse users out there the changes I have recently made to FitNesse. In doing so, I hope that these improvements will not benefit more teams using FitNesse but over time FitNesse will be moulded into a tool that really allows us to fully live the vision of specification, or even documentation, by example

The first in these series covers a new way to debug FitNesse when using C# and other .Net languages. It has always been possible to debug FitNesse using RunnerW.exe instead of Runner.exe, but it was fiddly to find the right process to connect to each time when using Visual Studio.

So while working with the team at Emendo, we decided it would be much easier to debug FitNesse if we started the runner through Visual Studio.

There's a few steps you'll need to go through to set it this up, but once you have done that it works like a charm and then debugging starts with two button clicks!


Debugging set up

Step 1: Tell FitNesse that when you remote debug you want to start the runner yourself.

Add the following line of wiki mark to the same page as where you tell fitnesse which dlls to use.

!define MANUALLY_START_TEST_RUNNER_ON_DEBUG {true}

Step 2: Configure Visual Studio to debug by starting runner.exe

In your Visual Studio project, go to the properties page and edit the debug page to start the runner.exe application when debugging.


Specifying the correct command line arguments for the runner is important. Luckily, FitNesse provides a way of finding out the settings that it is using – simply run the test you want to debug, and then click on the information icon at the top of the page (shown to the right of this paragraph).

Then you should see a page with a table like the following:

Copy the “command” string into the Visual studio, but first remove the first argument (since it is the runner and you have already specified it) and secondly make sure the last number is port 8085 – the default (but configurable) port that FitNesse expects to connect to when when it is running in debug mode.

Lastly, be sure to set the working directory to the one that FitNesse uses.

Setup is now complete!


Debugging a page

Now you are ready to debug your fitNesse test.

  1. Start test in FitNesse in Debug mode by either

      1. clicking your javascript browser shortcut, or

      2. Adding ?responder=test&remote_debug=true to the URL for the page

  2. Add breakpoints

  3. Start debugging within Visual Studio


This setup should continue to work for fine for all your tests, so long as they all use the same set of dlls. However if you find you add another FitNesse dll you will need to update your command line setting.

If you have any questions or can't get this to work, please post them as a comment or send them to the FitNesse newsgroup and I will try to answer them.

Happy debugging!

3 comments:

  1. hi there ...

    i usually create a DebugFixture

    public class DebugFixture
    {
    public DebugFixture()
    {
    System.Diagnostics.Debugger.Launch();
    }
    }

    and then i can add anywhere on the wiki code

    | Debug |

    cheers
    mike

    ReplyDelete
  2. Hi Clare,

    Do you have any idea on how to debug a fitnesse suite?
    Adding ?responder=test&remote_debug=true doesn't help at all...

    ReplyDelete
  3. Hi Annanth,

    To debug a suite you need to replace test with suite in the above link. So try:
    ?responder=suite&remote_debug=true

    Regards,
    Clare

    ReplyDelete