Friday, August 20, 2010

Nunit


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

(Various code-driven testing frameworks have come to be known collectively as xUnit. These frameworks allow testing of different elements (units) of software, such as functions and classes. The main advantage of xUnit frameworks is that they provide an automated solution with no need to write the same tests many times, and no need to remember what should be the result of each test. Such frameworks are based on a design by Kent Beck, originally implemented for Smalltalk as SUnit. Erich Gamma ported SUnit to Java, creating JUnit. Out of that the SUnit framework was also ported to other languages, e.g., CppUnit (for C++), NUnit (for .NET). They are all referred to as xUnit and are usually free, open source software. They are now available for many programming languages and development platforms).

Example

Example of an NUnit test fixture:
using NUnit.Framework;

[TestFixture]
public class ExampleTestOfNUnit
{
[Test]
public void TestMultiplication()
{
Assert.AreEqual(4, 2*2, "Multiplication");

// Equivalently, since version 2.4 NUnit offers a new and
// more intuitive assertion syntax based on constraint objects
// [http://www.nunit.org/index.php?p=constraintModel&r=2.4.7]:
Assert.That(2*2, Is.EqualTo(4), "Multiplication constraint-based");
}
}

No comments:

Post a Comment