Running NUnit Automatically in C# Express

A post on the TDD list asks about running NUnit tests using the Start button in Visual C# Express. In Visual Studio 2003 and 2005, you can set up a project’s Debug properties so that an arbitrary external program is executed. By selecting NUnit as that program and providing the correct command-line options, you can cause your tests to be run.

But in Visual C# 2005 Express, the only choice you have is to execute one of your own programs, with the result that this approach to running tests is unavailable. Of course, you could always run NUnit separately, as many of us do. Or you could set it up as an external tool using the Tools | External Tools… menu item, which works the same in the Express version as in the others.

But if you’re really attached to the approach using the Start button, all is not lost. You merely need a project of your own that runs the tests under NUnit. This is much easier than you might imagine. Just create an Windows executable and add a reference the nunit-gui-runner assembly. Replace the contents of Main() with a call to AppEntry.Main() with the same arguments you were passed. Here’s what it looks like…

using System;
using System.Windows.Forms;
namespace WindowsApplication2
    static class Program
        /// The main entry point for the application.
        static void Main(string[] args)

Make this project your startup project and set the commandline to point to the output of the project containing your tests. Use the /run option and any other options you like. When executed, this program will launch the NUnit GUI and run your tests.


  1. Charlie Says:

    Right after I posted this article, I saw a reply on the TDD list, posted by Errol Thompson. He explains that C# Express will actuall run an external program, if you can get the proper entries into the .user file for the project. You can read his post here:

  2. Debugging NUnit test within C# Express « Kenthall Development Team Says:

    […] What we have to do is explained on Charlie Poole’s blog on entitled Running NUnit Automatically in C# Express.  You basically fire up the GUI from inside a project.  Hence the reason for our Kenthall.TestHelper assembly, and that’s all it does for now. […]

  3. Jirka bianco Vágner » Debug unit testu pomoci Visual C# Express Says:

    […] Zdroje: Charlie Poole, Stewart Robertson […]

  4. C# Express NUnit « Life and times of the Mighty Anger Says:

    […] C# Express NUnit C# Express does not give you the ability to run through your nunits in debug. To mitigate your test-driven developments hassles, I came across this little workaround gem…. . You’ll have to mess around with the arguments after that but you get the point. […]

  5. EmPowerTec blog Says:

    Efficiently testing with NUnit and log4net

    I have used Nunit for testing .NET based software (libraries) for quite some time now but I have not been entirely happy due to three reasons:

    The only way to execute the tests was through nunit-gui or nunit-console. Both of these programs rea…