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

  

相关文章:

  • 2021-12-07
  • 2021-09-05
  • 2021-06-23
  • 2021-06-22
  • 2022-02-22
  • 2022-01-21
猜你喜欢
  • 2021-08-14
  • 2021-08-04
  • 2022-12-23
  • 2022-02-19
  • 2021-10-07
  • 2021-06-01
相关资源
相似解决方案