using System;
using NUnit.Framework;
[TestFixture]
public class SomeTests
{
}
}
使用TextFixture Attribute的class需要符合另一項唯一附加的限制,就是需要有一個public的default constructor(或者是沒有定義任何的constructor,這其實是相同的意思)。
TestFixtureSetUp 和TestFixtureTearDown簡介
這兩個主要用在TestFixture里面,其作用是提供一組函數執行任何測試運行之前(TestFixtureSetUP)和最后一個測試執行后(TestFixtureTearDown)。每一個TestFixture只能有一個TestFixtureSetUp方法和 TestFixtureTearDown方法。如果一個以上的TestFixtureSetUp和TestFixtureTearDown方法,可以通過編譯但是不會執行。注意一個TestFixture可以擁有一個TestFixtureSetUp和一個SetUp,也可以擁有一個 TestFixtureTearDown和一個TearDown方法。
TestFixtureSetUp 和 TestFixtureTearDown 被用在不方便使用SetUp和TearDown方法。
一般情況使用 SetUp 和TearDown attributes。
底下這段程序代碼示范了如何使用TestFixtureSetUp/TestFixtureTearDown
namespace UnitTestingExamples
{
using System;
using NUnit.Framework;
[TestFixture]
public class SomeTests
{
[TestFixtureSetUp]
public void RunBeforeAllTests()
{
文章來源于領測軟件測試網 http://www.kjueaiud.com/