Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

nunit

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.

like image 470
Mr Tree Avatar asked Sep 29 '11 11:09

Mr Tree


1 Answers

I don't 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 
    }
like image 196
Mattias Josefsson Avatar answered Oct 10 '22 17:10

Mattias Josefsson