How to run nUnit test suite with two different settings?

(Sorry for the fuzzy name, please edit it if you can come up with a better option)

I want to run the same tests in two different data stores, I can create data stores in the Setup () method.

So, should I have a superclass containing all the tests and the abstract SetUp() method, and then have a subclass for each data store?

Or is there a better way?

See " Case-insensitive comparison string with linq-to-sql and linq-to-objects " for what I'm testing.

+4
unit-testing nunit
Mar 05 '10 at 17:01
source share
1 answer

A simple solution is this.

All your test cases are in an abstract class, for example, in the TestBase class. For example:

 public abstract class TestBase { protected string SetupMethodWas = ""; [Test] public void ExampleTest() { Console.Out.WriteLine(SetupMethodWas); } // other test-cases } 

Then you create two subclasses for each installation. Thus, each subclass will be launched individually using the installation method and all inherited test methods.

 [TestFixture] class TestA : TestBase { [SetUp] public void Setup() { SetupMethodWas = "SetupOf-A"; } } [TestFixture] class TestB : TestBase { [SetUp] public void Setup() { SetupMethodWas = "TestB"; } } 

It is wonderful. However, for simpler tests, parameterized tests are the best solution.

+11
Mar 07 '10 at 22:29
source share



All Articles