简体   繁体   English

Nunit,C#:Test Fixture Teardown Nunit 的执行顺序

[英]Nunit , C# : Order of execution of Test Fixture Teardown Nunit

I have a test fixture class ABC which inherits from Base Class with name BaseTest.我有一个测试夹具 class ABC,它继承自 Base Class,名称为 BaseTest。 Both BaseTest and ABC has testfixture teardown and testfixture setup defined. BaseTest 和 ABC 都定义了 testfixture 拆卸和 testfixture 设置。

I want to know which TestFixtureSetUp and TestFixtureTearDown gets executed first.我想知道首先执行哪个 TestFixtureSetUp 和 TestFixtureTearDown 。 Please see the code below:请看下面的代码:

public class BaseTest 
{
  [TestFixtureSetup]
  public void BaseSetup()
  {
  }

  [TestFixtureTearDown]
  public void BaseTearDown()
  {
  }
}

 public class ABC : BaseTest
{
  [TestFixtureSetup]
  public void Setup()
  {
  }

  [TestFixtureTearDown]
  public void TearDown()
  {
  }
}

What i want to know is whether BaseTearDown gets executed first or TearDown?我想知道的是 BaseTearDown 是先执行还是 TearDown 执行?

The order of execution in this case is strictly defined by NUnit.这种情况下的执行顺序是由 NUnit 严格定义的。

Base class TestFixtureSetUp will always execute first, the the derived class TestFixtureSetUp. Base class TestFixtureSetUp 将始终首先执行,派生的 class TestFixtureSetUp。 TestFixtureTearDown methods execute in the reverse order: derived class first followed by bsse class. TestFixtureTearDown 方法以相反的顺序执行:派生的 class 首先是 bsse class。

Note that TestFixtureSetUp and TestFixtureTearDown are used in earlier releases of NUnit.请注意,TestFixtureSetUp 和 TestFixtureTearDown 用于 NUnit 的早期版本。 In more recent versions use OneTimeSetUp and OneTimeTearDown instead.在较新的版本中,改用 OneTimeSetUp 和 OneTimeTearDown。 The order of execution remains the same.执行顺序保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM