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
{
// ...
}
}
Imports System
Imports Nunit.Framework
Namespace Nunit.Tests
<TestFixture(), Category("LongRunning")>
Public Class LongRunningTests
' ...
End Class
End Namespace
#using <Nunit.Framework.dll>
using namespace System;
using namespace NUnit::Framework;
namespace NUnitTests
{
[TestFixture]
[Category("LongRunning")]
public __gc class LongRunningTests
{
// ...
};
}
#include "cppsample.h"
namespace NUnitTests {
// ...
}
package NUnit.Tests;
import System.*;
import NUnit.Framework.TestFixture;
/** @attribute NUnit.Framework.TestFixture() */
/** @attribute NUnit.Framework.Category("LongRunning") */
public class LongRunningTests
{
// ...
}
Test语法
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
public class SuccessTests
{
[Test]
[Category("Long")]
public void VeryLongTest()
{ /* ... */ }
}
Imports System
Imports Nunit.Framework
Namespace Nunit.Tests
<TestFixture()>
Public Class SuccessTests
<Test(), Category("Long")> Public Sub VeryLongTest()
' ...
End Sub
End Class
End Namespace
#using <Nunit.Framework.dll>
using namespace System;
using namespace NUnit::Framework;
namespace NUnitTests
{
[TestFixture]
public __gc class SuccessTests
{
[Test][Category("Long")] void VeryLongTest();
};
}
#include "cppsample.h"
namespace NUnitTests {
// ...
}
package NUnit.Tests;
import System.*;
import NUnit.Framework.TestFixture;
/** @attribute NUnit.Framework.TestFixture() */
public class SuccessTests
{
/** @attribute NUnit.Framework.Test() */
/** @attribute NUnit.Framework.Category("Long") */
public void VeryLongTest()
{ /* ... */ }
}