I have a basic Test setup using NUnit 2.6 and Visual NUnit in Visual Studio 2010. My problem is that when I’m running all tests it seems like the FixtureSetup method (which has the TestFixtureSetUpAttribute) is running one time for each of the tests.
I’ve also tried to put the Init code to the constructor, but it gives the same results.
The tests themselves reports their run time to runtime like 0.003 and 0.032 and so on.
[TestFixture]
public class MODatabaseTests
{
[TestFixtureSetUp]
public static void FixtureSetup()
{
// Perform heavy init (~1.5s)
}
[Test]
public void TestA()
{
...
}
[Test]
public void TestB()
{
...
}
}
If you add this code, you can confirm your suspicion:
The test runner may calling every test individually instead of treating a TestFixture as a suite of tests.
As an aside, I would avoid
staticin unit tests because if you have any static variables, their state would be carried from each run (though the fixture kind of wants this) and you lose the “unit” part of unit testing.