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()
{
Console.WriteLine( “TestFixtureSetUp” );
}
[TestFixtureTearDown]
public void RunAfterAllTests()
{
文章來源于領測軟件測試網 http://www.kjueaiud.com/