Saturday, July 23, 2011

Debugging with Nunit and Visual Studio Express

It's possible to set breakpoints in unit tests in the freebie versions of MS Visual Studio:
  1. add a reference to the C:\Program Files\NUnit 2.5.10\bin\net-2.0\lib\nunit-console-runner.dll to your test project
  2. add the following class to your test project
  3. using System;
    namespace MyTests
    {
        class NUnitDebugRunner
        {
            [STAThread]
            static void Main(string[] args)
            {
                NUnit.ConsoleRunner.Runner.Main(args);
            }
        }
    }

  4. in the test project properties, under 'Application' set the output type as 'Windows Application and the Startup objects as the class created in the previous step. Under the debug tab, browse to the folder containing the csproj for the test project in the 'Working directory' field and put the name of the csproj file in the C'Command line arguments' field
  5. set the test project as the startup project
Now when you hit F5, any breakpoints in the tests will be hit.

Thanks to Blokley

No comments:

Post a Comment