In the previous chapter we briefly introduced NUnit's introductory example "Step by step NUnit (1)", so that everyone has a simple understanding of nunit.
The use of NUnit is very simple, but there are many best practices when it is used in a project. In this chapter we introduce some of the configurations and characteristics of the nunit that are not mentioned in the previous chapter.
To skillfully use nunit or to use and experience in practice, it is no use simply to learn knowledge points.
OK, no more nonsense. Continue the contents of the previous chapter.
In Visual Studio 2008, open the example in the previous chapter, the Calculator class has 4 simplest methods: Add, subtract, multiply, and divide. The four methods in the Calculatortest class are unit tests of the four methods of the Calculator class.
[Testfixture]
public class calculatortest ...
{
[Test] public
void Testadd ()
... {
Calculator cal = new Calculator ();
int expected = 5;
int actual = cal. ADD (2, 3);
Assert.AreEqual (expected, actual);
[Test] public
void Testminus () ...
{
Calculator cal = new Calculator ();
int expected = 5;
int actual = cal. Minus (5);
Assert.AreEqual (expected, actual);
[Test] public
void testmultiply () ...
{
Calculator cal = new Calculator ();
int expected = 5;
int actual = cal. Multiply (1, 5);
Assert.AreEqual (expected, actual);
[Test] public
void Testdivide () ...
{
Calculator cal = new Calculator ();
int expected = 5;
int actual = cal. Divide (5);
Assert.AreEqual (expected, actual);
}
}