CategoryAttribute (NUnit 2.2)

Category提供了一个套件的其他方法来处理测试的分组。不管是单个测试案例还是测试fixture,都可以将它们指定为属于某个特定的分类。不管是GUI还是控制台测试运行器,允许指定运行包含或排除一系列的分类。当使用分类时,仅有可选目录的测试可以运行。这些没有选择的组的测试是不会报告的。

在控制台运行器里通过/include以及/exclude参数的使用以及在GUI里通过一个单独的“Categories"标签,这个特性也是可以使用的。在任何时候,GUI提供一个已选目录的可视化描述。

Test Fixture语法

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

  [TestFixture]
  [Category("LongRunning")]
  public class LongRunningTests
  {
    // ...
  }
}

Test语法

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

  [TestFixture]
  public class SuccessTests
  {
    [Test]
    [Category("Long")]
    public void VeryLongTest()
    { /* ... */ }
}