Unit Testing with NUnit—Test cases


Jump to: navigation, search
CSharp-Online.NET:Articles
Visual Studio Articles

Unit Testing with NUnit

© 2004 O'Reilly & Assoc., Inc.

Test cases

A test is the lowest building block of unit testing and tests a single piece of software functionality. Programmatically, a test corresponds to a method in the unit test code.

You identify a test by decorating a method with the [Test] attribute. For example:

[Test]
public void Test1( )
{
   // test case implementation
}

A test method must be public (so that the test runner can locate it using reflection), returns void, and take no arguments. A unit test performs one or more assertions that determine whether the functionality being tested works properly. An assertion simply tests an actual post-condition against the expected post-condition required for the test to pass. Assertions are described later in "Assertions."

The [Test] attribute has an optional argument named Description that defines the description that appears in the test properties dialog in the test runner GUI. For example:

[Test (Description = "MyTest")]
WARNING
For backward compatibility with earlier versions of NUnit, a method is automatically identified by NUnit as a test if the first four characters of the method name are "test" this identification is not case sensitive.


Previous_Page_.gif Next_Page_.gif


Personal tools