Skip the SetUp method only for a particular test in NUnit?

后端 未结 6 1849
时光说笑
时光说笑 2021-01-01 19:47

I have a test where I do not need to run the SetUp method (attributed with [SetUp]) before running the test. I need the SetUp method t

6条回答
  •  无人及你
    2021-01-01 19:50

    You can have the main SetUp in a base class:

    [SetUp]
    public virtual void SetUp()
    {
      // Set up things here
    }
    

    ...and then override it in the class where you have the tests that should not run the SetUp code:

    [SetUp]
    public override void SetUp()
    {
      // By not calling base.SetUp() here, the base SetUp will not run
    }
    

提交回复
热议问题