繁体   English   中英

Nunit基础文本装置及其运行顺序

[英]Nunit Base Text Fixtures and the order in which they run

如果我有:

[TestFixture]
public class BaseTestFixture
{
  [TestFixtureSetup]
  public void SetUpStuff()
  {

  }
}

[TestFixture]
public class DeriveTestFixture : BaseTextFixture
{
   [TestFixtureSetup]
   public void SetupOtherStuff()
   {
   } 
}

是否在DerivedTestFixture TestFixtureSetUp方法之前或之后调用BaseTextFixture TestFixtureSetup方法?

为什么不通过测试向自己证明呢?

    [TestFixture]
    public class BaseTestFixture
    {
      [TestFixtureSetup]
      public void SetUpStuff()
      {
         Console.Writeline("Base");
      }
    }

    [TestFixture]
    public class DeriveTestFixture : BaseTextFixture
    {
       [TestFixtureSetup]
       public void SetupOtherStuff()
       {
         Console.Writeline("Derived");
       } 
    }

就是说,您可能会考虑只在基础上具有属性,并具有其他两个要覆盖的函数(例如OnAfterTestFixtureSetup()),以便更加明确。 那是,

[TestFixture]
    public class BaseTextFixture
    {
      [TestFixtureSetup]
      public void SetUpStuff()
      {
         Console.Writeline("Base");
        OnAfterTextFixtureSetup();
      }

      public virtual OnAfterTextFixtureSetup()
      {

      }
}

暂无
暂无

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

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