Home Download Documentation Getting Started Support Other Versions

Test Attribute

All test need to comply with some rules so that they can be found and executed by the unit testing framework. csUnit is no different.

In it's most basic form each test must be public, take no parameters, and must be of type void. csUnit also supports parameterized tests, which take any number of parametes. This is, however, an advanced feature and therefore not discussed here.

Generally, csUnit uses reflection to scan test assemblies. If the test implementation follows the rules, csUnit will find the test and will be able to execute it.

There are two ways to indicate to csUnit that a method is a test:

  • Based on naming convention
  • Using an attribute

If you decide to go for the name convention, then you need to prefix each test with the term "Test", for instance:

[TestFixture]
public class MyFirstFixture {
   public void TestMyFirstTest() {
      ...
   }
}

In this example csUnit finds this test based on it's name.

The second and more flexible option is to use the test attribute to mark a method as a test. In this case the name can be anything you like. An example would be:

[TestFixture]
public class MyFirstFixture {
   [Test]
   public void MyFirstSecondTest() {
      ...
   }
}

Here csUnit will be able to find the test because it has been marked with the TestAttribute, or in short Test. The C# programming language allows you to take the shortcut and omit the postfix "Attribute".

Sponsors:

Extreme Simplicity Logo

Agile Utilities Logo


Sources hosted by

Get csUnit - unit testing for .NET at SourceForge.net. Fast, secure and Free Open Source software downloads



Copyright © 2002-2009 by Agile Utilities NZ Ltd. All rights reserved. Site design by Andreas Weiss. This site is protected by bot traps.