This section provides an overview of what nunit is, and why a developer might want to use it.
It should also mention any large subjects within nunit, and link out to the related topics. Since the Documentation for nunit is new, you may need to create initial versions of those related topics.
Version | Release Date |
---|---|
2.2 | 2004-08-08 |
2.2.1 | 2004-10-26 |
2.2.2 | 2004-12-07 |
2.2.3 | 2005-02-14 |
2.2.4 | 2005-12-14 |
2.2.5 | 2005-12-22 |
2.2.6 | 2006-01-21 |
2.2.7 | 2006-02-18 |
2.2.8 | 2006-04-21 |
2.2.9 | 2006-11-26 |
2.2.10 | 2007-03-15 |
2.4 RC1 | 2007-02-25 |
2.4 (Final Release) | 2007-03-16 |
2.4.1 | 2007-05-03 |
2.4.2 | 2007-08-02 |
2.4.4 | 2007-10-20 |
2.4.5 | 2007-11-23 |
2.4.6 | 2007-12-31 |
2.4.7 | 2008-03-30 |
2.4.8 | 2008-07-21 |
2.5 | 2009-05-02 |
2.5.1 | 2009-07-08 |
2.5.2 | 2009-08-10 |
2.5.3 | 2009-12-11 |
2.5.4 | 2010-04-08 |
2.5.5 | 2010-04-22 |
2.5.6 | 2010-07-24 |
2.5.7 | 2010-08-01 |
2.5.8 | 2010-10-14 |
2.5.9 | 2010-12-14 |
2.5.10 | 2011-04-02 |
2.6 | 2012-02-20 |
2.6.1 | 2012-08-04 |
2.6.2 | 2012-10-22 |
2.6.3 | 2013-10-10 |
2.6.4 | 2014-12-16 |
3.0 (Alpha 1) | 2014-09-22 |
3.0 (Beta 1) | 2015-03-25 |
3.0 RC1 | 2015-11-01 |
3.0.0 Final Release | 2015-11-15 |
3.0.1 | 2015-12-01 |
3.2 | 2016-03-05 |
3.2.1 | 2016-04-19 |
3.4 | 2016-06-25 |
[TestFixture]
public class UnitTest1
{
class Message
{
public string Text { get; } = "Hello World";
}
[Test]
public void HelloWorldTest()
{
// Act
var message = new Message();
// Assert
Assert.That(message.Text, Is.EqualTo("Hello World"));
}
}
Install-Package NUnit
This package includes all assemblies needed to create unit tests.
Tests can be executed using one of the following methods:
To execute tests using the Visual Studio Unit Test Window, install the NUnit 3 Test Adapter. https://visualstudiogallery.msdn.microsoft.com/0da0f6bd-9bb6-4ae3-87a8-537788622f2d
Install the NUnit Console Runner via NuGet
Install-Package NUnit.Console
The executable nunit3-console.exe is located in packages\NUnit.3.X.X\tools
[TestCase(0, 0, 0)]
[TestCase(34, 25, 59)]
[TestCase(-1250, 10000, 8750)]
public void AddNumbersTest(int a, int b, int expected)
{
// Act
int result = a + b;
// Assert
Assert.That(result, Is.EqualTo(expected));
}
Ever wondered why you cannot use Assert.Equals() for both Nunit and MSTest. If you have not then maybe as a start you need to be aware that you cannot use this method. Instead you would use Assert.AreEqual() to compare two objects for equality.
The reason here is very simple. Like any class the Assert class is inheriting from System.Object that has a public virtual Equals method meant to check if a given object is equal to the current object. Therefor calling that equals method would be a mistake as in a unit test you would instead to compare two objects that have nothing to do with the Assert class. As a result Nunit and MSTest both chose to provide a method Assert.AreEqual for that purpose.
Furthermore to ensure that you do not use the Equals method by mistake they have decided to throw Exceptions to warn you if you do use this by mistake.
Nunit Implementation:
[EditorBrowsable(EditorBrowsableState.Never)]
public static new bool Equals(object a, object b)
{
// TODO: This should probably be InvalidOperationException
throw new AssertionException("Assert.Equals should not be used for Assertions");
}