Click here to Skip to main content
15,844,759 members
Articles / Programming Languages / C#

Easy Debugging of NUnit Tests from Visual Studio 2008 Professional

Rate me:
Please Sign up or sign in to vote.
4.09/5 (8 votes)
23 Jun 2009Apache1 min read 157.4K   42   54
How to easily debug NUnit tests in Visual Studio 2008 professional edition

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

  1. Download the latest release from here.
  2. Run the installer.
  3. Start Visual Studio 2008.
  4. Select from Menu View->Other Windows->NUnit View.
  5. Place the view to location of your choice.

Image 1

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:

  1. Download NUnit 2.5 from here.
  2. Add nunit.framework.dll to your projects references.
  3. Add test case to the project (See example below).
  4. Make sure your project dependencies have copy local properties set.
  5. Build the project.
  6. To start debugging, click the arrow button of a test row in the NUnit View.
  7. 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.

C#
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

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Architect
Finland Finland
Web and rich client solutions since 2002 with .NET and Java.

Open source contributor to Visual Nunit, OpenSimulator, MXP protocol and IdealistViewer.

Comments and Discussions

 
GeneralRe: Visual Nunit 1.0 RC 1 Released [modified] Pin
Tommi Laukkanen6-Jul-09 4:23
Tommi Laukkanen6-Jul-09 4:23 
QuestionVisual Studio 2005? Pin
DrMcClelland2-Jul-09 6:02
DrMcClelland2-Jul-09 6:02 
AnswerRe: Visual Studio 2005? Pin
Tommi Laukkanen2-Jul-09 10:13
Tommi Laukkanen2-Jul-09 10:13 
GeneralRe: Visual Studio 2005? Pin
gtmxxl3-Jul-09 1:36
gtmxxl3-Jul-09 1:36 
GeneralRe: Visual Studio 2005? Pin
Tommi Laukkanen3-Jul-09 8:56
Tommi Laukkanen3-Jul-09 8:56 
GeneralCrash Pin
gtmxxl2-Jul-09 5:07
gtmxxl2-Jul-09 5:07 
GeneralRe: Crash Pin
Tommi Laukkanen2-Jul-09 10:14
Tommi Laukkanen2-Jul-09 10:14 
GeneralMy vote of 1 Pin
JRASPEN29-Jun-09 20:27
professionalJRASPEN29-Jun-09 20:27 
code crashes
GeneralCrash When loading Pin
JRASPEN24-Jun-09 12:09
professionalJRASPEN24-Jun-09 12:09 
GeneralRe: Crash When loading Pin
Tommi Laukkanen1-Jul-09 20:06
Tommi Laukkanen1-Jul-09 20:06 
GeneralRe: Crash When loading Pin
Tommi Laukkanen1-Jul-09 20:44
Tommi Laukkanen1-Jul-09 20:44 
GeneralVersion 0.9 Released Pin
Tommi Laukkanen23-Jun-09 21:35
Tommi Laukkanen23-Jun-09 21:35 
GeneralVS Standard Edition Pin
Daniel M. Camenzind22-Jun-09 21:01
Daniel M. Camenzind22-Jun-09 21:01 
GeneralRe: VS Standard Edition Pin
Tommi Laukkanen22-Jun-09 21:20
Tommi Laukkanen22-Jun-09 21:20 
GeneralRe: VS Standard Edition Pin
Daniel M. Camenzind22-Jun-09 21:53
Daniel M. Camenzind22-Jun-09 21:53 
GeneralRe: VS Standard Edition Pin
Tommi Laukkanen22-Jun-09 23:33
Tommi Laukkanen22-Jun-09 23:33 
GeneralNUnit vs .. mbUnit, vs xUnit Pin
torial22-Jun-09 16:17
torial22-Jun-09 16:17 
GeneralRe: NUnit vs .. mbUnit, vs xUnit Pin
Tommi Laukkanen22-Jun-09 21:16
Tommi Laukkanen22-Jun-09 21:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.