NUnit


NUnit is an open-source unit testing framework for the.NET Framework and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many programs in the xUnit family.

Features

NUnit provides a console runner, which is used for batch execution of tests. The console runner works through the NUnit Test Engine, which provides it with the ability to load, explore and execute tests. When tests are to be run in a separate process, the engine makes use of the nunit-agent program to run them.
The NUnitLite runner may be used in situations where a simpler runner is more suitable. It allows developers to create self-executing tests.

Assertions

NUnit provides a rich set of assertions as static methods of the Assert class. If an assertion fails, the method call does not return and an error is reported. If a test contains multiple assertions, any that follow the one that failed will not be executed. For this reason, it's usually best to try for one assertion per test.
Nunit 3.x is supporting multiple assertions.

public void ComplexNumberTest

Classical

Before NUnit 2.4, a separate method of the Assert class was used for each different assertion. It continues to be supported in NUnit, since many people prefer it.
Each assert method may be called without a message, with a simple text message or with a message and arguments. In the last case the message is formatted using the provided text and arguments.

// Equality asserts
Assert.AreEqual;
Assert.AreEqual;
Assert.AreNotEqual;
Assert.AreNotEqual;
// Identity asserts
Assert.AreSame;
Assert.AreSame;
Assert.AreNotSame;
Assert.AreNotSame;
// Condition asserts
//
Assert.IsTrue;
Assert.IsFalse;
Assert.IsNull;
Assert.IsNotNull;
Assert.IsNaN;
Assert.IsEmpty;
Assert.IsNotEmpty;
Assert.IsEmpty;
Assert.IsNotEmpty;

Constraint based

Beginning with NUnit 2.4, a new Constraint-based model was introduced. This approach uses a single method of the Assert class for all assertions, passing a Constraint object that specifies the test to be performed. This constraint-based model is now used internally by NUnit for all assertions. The methods of the classic approach have been re-implemented on top of this new model.

Example

Example of an NUnit test fixture:

using NUnit.Framework;
public class ExampleTestOfNUnit
// The following example shows different ways of writing the same exception test.
public class AssertThrowsTests
// This example shows use of the return value to perform additional verification of the exception.
public class UsingReturnValue
// This example does the same thing using the overload that includes a constraint.
public class UsingConstraint

The NUnit framework discovers the method ExampleTestOfNUnit.TestMultiplication automatically by reflection.

Extensions

FireBenchmarks is an addin able to record execution time of unit tests and generate XML, CSV, XHTML performances reports with charts and history tracking. Its main purpose is to enable a developer or a team that work with an agile methodology to integrate performance metrics and analysis into the unit testing environment, to easily control and monitor the evolution of a software system in terms of algorithmic complexity and system resources load.
NUnit.Forms is an expansion to the core NUnit framework and is also open source. It specifically looks at expanding NUnit to be able to handle testing user interface elements in Windows Forms. As of January 2013, Nunit.Forms is in Alpha release, and no versions have been released since May 2006.
NUnit.ASP is a discontinued expansion to the core NUnit framework and is also open source. It specifically looks at expanding NUnit to be able to handle testing user interface elements in ASP.Net.