I went through the process of working out how to get started with NUnit a couple of days ago, and it isn't obvious how to get started.
First install NUnit.
To make unit tests, first add a new Class Library project to the solution. Add a reference to nunit.framework
by right-clicking on References in the Solution Explorer and finding it in the .NET tab. Add a reference to the project you want to test (this will be in the Projects tab). Inside the test class, you will be to be using NUnit.Framework and the project you want to test. Then create unit tests. For example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using NUnit.Framework;
using PrimeGenerator; // my project
namespace NUnitTestProject
{
[TestFixture]
public class Tests
{
[Test]
public void NaiveTest()
{
int n = 5;
ArrayList results = Program.generatePrimesNaive(n); // this is a static method that generates the first n primes
ArrayList expected = new ArrayList();
expected.Add(2);
expected.Add(3);
expected.Add(5);
expected.Add(7);
expected.Add(10);
Assert.AreEqual(expected, results);
}
}
}
To run tests, open NUnit and open the compiled class library. In my case, this is \NUnitTestProject\bin\Debug\NUnitTestProject.dll
. Tests can now be run. Alternatively, tests can be run from inside Visual Studio with TestDriven.Net. Simply right-click and select Run Test(s).