NUnit also provides test runner applications that execute the tests and
report the results.
1 There are many options for locating libraries: they can be in the same directory as the application,
or in a special .NET directory called the Global Assembly Cache (GAC), or in a directory
identified by one of the .NET .config files.
2 Some editions of Microsoft Visual Studio include a similar unit testing tool.
24 Why We Need Model-Based Testing
using System;
using NUnit.Framework;
namespace ClientServerImpl
{
// Test fixture for remote instrument Server, Client, Temperature classes
[TestFixture]
public class Tests
{
#region [SetUp], [TearDown] methods (code not shown)
// Check Fahrenheit to Celsius conversion, one data point
[Test]
[Category("Convert")]
public void Convert32()
{
Assert.AreEqual(Temperature.ConvertToCelsius(32), 0);
}
// Check Fahrenheit to Celsius conversion, several data points
[Test]
[Category("Convert")]
public void ConvertMany()
{
Assert.AreEqual(Temperature.ConvertToCelsius(32), 0);
Assert.AreEqual(Temperature.ConvertToCelsius(98.6), 37);
Assert.AreEqual(Temperature.ConvertToCelsius(212), 100);
Assert.AreEqual(Temperature.ConvertToCelsius(212), 101); //Fail!
}
#region Other tests (code not shown)
}
}
Figure 2.9. Test fixture with test methods.
To write unit tests for NUnit, code a test fixture class that has test methods.
Pages:
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56