Update: August 22, 2007

SuiteAttribute (NUnit 2.0)

The Suite Attribute is used to define subsets of suites based on user preference. It was introduced in NUnit 2.0 to replace inheritance from the TestSuite class.

Originally, the NUnit developers believed that the need for the Suite mechanism would diminish because of the dynamic creation of suites based on namespaces. It was provided for backwards compatibility.

That has not proven to be true. Suites are still used today by many people, so we are making an effort to revive them in terms of usability. The current release supports suites using the classic mechanism: a static property with the SuiteAttribute returns a TestSuite, populated with the tests that are to be executed.

This approach currently has some limitations, which we hope to remove in a future NUnit release:

  1. Creating a suite requires a reference to the nunit.core assembly, which is not normally referenced by user tests. This means that the tests can not be ported across versions of NUnit without recompilation.

  2. There is currently no easy way to run user-defined suites as a part of a larger run. They were originally intended as a way to define a set of tests at the top level and so can only be used by specifying them on the command-line with the /fixture option.

Example:

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;
  using NUnit.Core;

  public class AllTests
  {
    [Suite]
    public static TestSuite Suite
    {
      get
      {
        TestSuite suite = new TestSuite("All Tests");
        suite.Add(new OneTestCase());
        suite.Add(new Assemblies.AssemblyTests());
        suite.Add(new AssertionTest());
        return suite;
      }
    }
  }
}