TestAttribute (NUnit 2.0)
Test属性标记某个类的某个方法为一个测试方法,此类已经标记为一个TestFixture。为了与较早的NUnit版本向后兼容,可以发现测试方法的头4个字母“test”是不考虑大小的。
一个测试方法的签名定义如下:
public void MethodName()
注意这里必须没有参数。如果程序员将测试方法标记为不正确的签名,它不会运行,而且会出现在运行程序的UI的TestNotRun区域。
实例:
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
public class SuccessTests
{
[Test] public void Add()
{ /* ... */ }
public void TestSubtract()
{ /* backwards compatibility */ }
}
}
Imports System
Imports Nunit.Framework
Namespace Nunit.Tests
<TestFixture()> Public Class SuccessTests
<Test()> Public Sub Add()
' ...
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] void Add();
};
}
#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() */
public void Add()
{ /* ... */ }
}