Basic knowledge of unit testing
A unit test is a small piece of code written by a developer to verify that a small, well-defined function of the measured code is correct. Typically, a unit test is used to determine the behavior of a particular function under a particular condition (or scene). For example, you might put a large value in an ordered list, and then confirm that the value appears at the end of the list. Alternatively, you might remove the character from the string that matches a pattern, and then confirm that the string does not contain the characters anymore.
The unit test is performed to prove that the behavior of a piece of code is exactly the same as what the developer expects.
When writing a project, if we assume that the underlying code is correct, the underlying code is first used in high-level code, and then the high-level code is used by higher-level code, and so forth. When basic underlying code is no longer reliable, the necessary changes cannot be confined to the bottom. Although you can fix the underlying problem, these changes to the underlying code will inevitably affect the high-level code. As a result, a correction to the underlying code could lead to a series of changes to almost any code, making the modifications more and more complex. So that the entire project also failed.
and the core of unit testing: the simple and effective technique is to make the code more perfect.
NUnit Introduction
NUnit is a free, open source (http://www.nunit.org) product that provides a set of test frameworks and a test run program (Beta runner).
Note: Test Tunner knows how to find the [test] method in classes and classes that have [Testfixture] properties.
How to install NUnit
In the official website http://www.nunit.org/index.php?p=download download NUnit, the current version is 2.4.8, I under IS nunit-2.4.8-net-2.0.zip.
NUnit First Demo
We create a new NUnit project with Visual Studio 2008