這個attribute你大概不會經常用的,但是一旦需要的時候,這個attribute是很方便使用的。你可以使用這個attribute來標示某個test method,叫Test Runner在執行的時候,略過這個method不要執行。使用這個Ignore attribute的方法如下:
namespace UnitTestingExamples
{
using System;
using NUnit.Framework;
[TestFixture]
public class SomeTests
{
[Test]
[Ignore("We're skipping this one for now.")]
public void TestOne()
{
// Do something...
}
}
}
如果你想要暫時性的comment out一個test method的話,你應該考慮使用這個attribute。這個attribute讓你保留你的test method,在Test Runner的執行結果里面,也會提醒你這個被略過的test method的存在。
NUnit Assert Class簡介
除了以上所提到的這些用來標示測試程序所在的attributes之外,NUnit還有一個重要的class你應該要知道如何使用。這個class就是Assert class。Assert class提供了一系列的static methods,讓你可以用來驗證主要程序的結果與你所預期的是否一樣。Assert class代替了舊的Assertion class,下面是這個類的方法:
Assert.IsTrue( bool );
文章來源于領測軟件測試網 http://www.kjueaiud.com/