NUnit TestFixtureSetup 和 TestFixtureTearDown

TestFixtureSetup 和 TestFixtureTearDown

在所有测试开始前(TestFixtureSetup)或结束后(TestFixtureTearDown)运行一 次。记住他只运行一次,而不论有多少个Test函数。因此一个TestFixture只能有一个TestFixtureSetup或TestFixtureTearDown。

示例: 测试用例

[TestFixture]
public class TestFixtureSetUpAndTearDownTest
{
[TestFixtureSetUp]
public void RunBeforeAllTests()
{
Console.WriteLine( "TestFixtureSetUp" );
}
[TestFixtureTearDown]
public void RunAfterAllTests()
{
Console.WriteLine( "TestFixtureTearDown" );
}
[SetUp]
public void RunBeforeEachTest()
{
Console.WriteLine( "SetUp" );
}
[TearDown]
public void RunAfterEachTest()
{
Console.WriteLine( "TearDown" );
}
[Test]
public void Test1()
{
Console.WriteLine( "Test1" );
}
 
被测试类
[Test]
public void Test2()
{
Console.WriteLine( "Test2" );
}
}
运行结果:
TestFixtureSetUp
SetUp
Test2
TearDown
TestFixtureTearDown

  

你可能感兴趣的:(unit test)