Introduction
This article describes a convenient way of debugging NUnit tests using open source plugin to Visual Studio 2008. Many open source and cross platform projects choose NUnit testing framework for mono and nant support.
Background
Visual Nunit plugin for Visual Studio 2008 was developed to speed up development of MXP protocol reference implementation. Being able to debug unit tests easily from integrated development environment is a big efficiency factor.
Installation
- Download the latest release from here.
- Run the installer.
- Start Visual Studio 2008.
- Select from Menu View->Other Windows->NUnit View.
- Place the view to location of your choice.
Debugging Process
The debugging with Visual Nunit is achieved by simply double clicking the test at NUnit View. To create test cases to your project, do the following steps:
- Download NUnit 2.5 from here.
- Add nunit.framework.dll to your projects references.
- Add test case to the project (See example below).
- Make sure your project dependencies have copy local properties set.
- Build the project.
- To start debugging, click the arrow button of a test row in the NUnit View.
- Proceed as normal with Visual Studio Debugging.
Stopping debug will terminate the nunit runner process if your unit test is hanging or if you do not wish to wait until it is completed.
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Diagnostics;
using System.Threading;
namespace NunitTests
{
[TestFixture]
public class ExampleTestFixture
{
[Test]
public void TestSuccess()
{
Trace.TraceInformation("Test trace.");
}
[Test]
public void TestException()
{
throw new Exception("Test Exception");
}
[Test]
public void TestAssert()
{
Assert.Fail("Test Assert");
}
[Test]
public void TestHang()
{
Thread.Sleep(10000);
}
}
}
Points of Interest
Visual Nunit was written with Microsoft Visual Studio 2008 SDK. The project type is Visual Studio Integration Package and the sources are available as open source project from here.
History
- 21st June 2009 - Initial version