NUnit - does not work with TestFixtureSetUp method which is not allowed on SetUpFixture
I'm trying to refactor the Integration Tests that we have, so they use a common class to create the database and data required in the database for testing in other classes in the same assembly using the [SetUpFixture] NUnit attribute.
I have:
namespace Tests;
public class TestBaseClass : SolutionBaseClass
{
public void Setup()
{
base.CreateDatabase();
base.CreateData();
}
public void Teardown()
{
base.DestroyDatabase();
}
}
[SetUpFixture]
public class Setup : TestBaseClass
{
[SetUp]
public void Setup()
{
base.Setup();
}
[TearDown]
public void Teardown()
{
base.Teardown();
}
}
then the individual classes of test instruments:
namespace Tests.Services;
[TestFixture]
public class LibraryTest : TestBaseClass
{
[TestFixtureSetUp]
public void SetupTests()
{
// I know am calling the same Setup twice once from SetUpFixture and TestFixture,
// I have handled it so that only one Database/Data gets set up once (for safety mostly!)
base.SetUp();
// Other class initialisations.
}
}
Any ideas what I am doing wrong, I suppose this is a problem with the inheritance model being used as you can tell that I am inheriting this from someone else !!
Thank.
+3
source to share
1 answer
In NUnit 3, use OneTimeSetUpAttribute and OneTimeTearDownAttribute for static methods of the [SetUpFixture] class. An example can be found here: http://bartwullems.blogspot.nl/2015/12/upgrading-to-nunit-30-onetimesetup.html
+3
source to share