Monday, September 17, 2007

Launch NUnit Tests directly from Visual Studio and Debug

Launching tests directly from Visual Studio is very comfortable feature. Developers, who are familiar with test driven development, need to launch tests frequently, so this feature is necessary for them.

My favourite testing framework is NUnit. Tests in this framework are launched from external application with perfect GUI.

In this article I will demonstrate how to start external application from Visual Studio, e.g. NUnit GUI, and keep running debugger. Debugging NUnit tests is very significant advantage because standard GUI of NUnit framework does not support it.

So, suppose that you have created a class library project with the following NUnit test:

using System.IO;

using NUnit.Framework;

using NUnit.Framework.SyntaxHelpers;

 

namespace DirectNUnit

{

  [TestFixture]

  public class Tests

  {

    [Test]

    public void Test()

    {

      string combinedPath = Path.Combine(@"C:\Projects", @"HelloWorld");

      Assert.That(combinedPath, Is.EqualTo(@"C:\Projects\HelloWorld"));

    }

  }

}



Now, you want to start this test directly from Visual Studio and use some breakpoints in the test. You can do it without any VS plug-in, just edit project settings. Open Project | Properties | Debug and set values like this:



Enter Start external program and Command line arguments, that is the path to the assembly containing your test.

For launching NUnit GUI and debugging tests press F5.

kick it on DotNetKicks.com

2 comments:

Inv said...

Nice and simple, thanks!

adolfogu said...

Great work!