Thursday, September 14, 2006

Debugging NUnit in Visual Studio Express

Early on into developing with the Visual Studio Express Editions the lack of support for a few things become quickly obvious. Namely, no Add-In support and no ability for the debugger to attach to a process.

Well the first one I heard has been overcome for certain tools (well briefly anyway).
As to the second issue I found a workaround on my net travels - thought it would be good to document it here.

Basically you modify the .csproj.user file to include this snippet

<StartProgram>C:\Program Files\NUnit-Net-2.0 2.2.8\bin\nunit-gui.exe</StartProgram>

under the PropertyGroup element.

Now when you press 'F5' it should fire up a debuggable NUnit session.
This could be used to fire up any process - Windows Live Writer instances to test your plug-ins for instance ;)

Note: Untested by me as of yet - will test when I get a chance and I'll remove this note.


  1. Anonymous12:02 AM

    Thanks for the tip - I got this to work with some refinement.

  2. blokeley2:10 AM

    There is an easy way to debug NUnit tests from Visual C# Express, which has the advantages of:
    * not invoking the NUnit GUI; and
    * not popping up an external console window; and
    * piping output to Visual Studio's output window; and
    * not requiring hacking the .csproj file...


    0. Add a reference to nunit-console-runner in your test assembly.

    1. In your test assembly, make a class with the following one liner:

    using System;

    namespace MotorExampleTests

    // Written by blokeley
    class NUnitConsoleRunner
    static void Main(string[] args)

    2. Open your test assembly's properties. For example, right-click on the assembly and select Properties.

    3. On the Application tab, select Output Type: Windows Application; and Startup Object: NUNitConolseRunner (the file above).

    4. On the Debug tab, enter the .csproj file name in Command Line Arguments; and browse to the folder of the .csproj file in Working Directory.

    5. Save everything, set a breakpoint and run using F5 or the green arrow button.

  3. that's a great tip!

    Thanks! Saved me a lot of time

  4. Anonymous3:39 AM

    I can't put "nunit-console-runner" on startup object ?
    I just can put my assembly ...

  5. Gooooood tip. Thank alot.

  6. Anonymous1:33 AM

    I tried this and it works like a charm. However, when a test fails, I am unable to click on the failing test and automatically go to the file and line number that asserted. Is there a way to format the test output for this to work?