NUnit: SetUp and TearDown for each test in a test fixture across multiple Fixtures

為{幸葍}努か 提交于 2020-07-20 10:40:14

问题


I would like to have a generic SetUp and TearDown that is run with every test across multiple fixtures but all within a common namespace. This would be something similar to the [SetUpFixture] attribute but would be run with every test.

I've tried using a base class with [SetUp] but resharper resolves this as inconclusive which isn't really ideal.


回答1:


I dont see any problem in using a base class with the generic code.

public class BaseTest 
{
[SetUp] 
public void SetUp()
{ 
    //Do generic Stuff 
}

[TearDown] 
public void TearDown()
{
  // Do generic stuff 
}



[TestFixture]
public class TestClass : BaseTest
{
 [SetUp] 
public void SetUp()
{ 
    //Do Stuff 
}

[TearDown] 
public void TearDown()
{
  // Do stuff 
}


来源:https://stackoverflow.com/questions/7596447/nunit-setup-and-teardown-for-each-test-in-a-test-fixture-across-multiple-fixtur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!