I have a project with several TestFixture and I want to define the same [SetUp] [TearDown] methods for every test. Considering I have many TestFixture I want to avoid editing all my files to add the two instructions.
Browsing the nunit documentation I thought [SetUpFixture] was the perfect solution. So I copied the example and tried to run it but it seems my TearDown method is never being runned whereas the SetUp is executing as I would expect. To assert this I simply used throw statements.
My questions are :
- Am I wrong with my use case ? Should I do things differently to reach my goal ?
- Am I making an incorrect usage of SetUpFixture attribute ?
Below is my SetUpFixture class. I am using Nunit 3.11.
using System;
using NUnit.Framework;
namespace MyTestProject
{
[SetUpFixture]
public class MySetUpClass
{
[OneTimeSetUp]
public void RunBeforeAnyTests()
{
StaticClass.Init();
// throw new InvalidOperationException("SetUp reached");
}
[OneTimeTearDown]
public void RunAfterAnyTests()
{
StaticClass.Finalize();
// throw new InvalidOperationException("TearDown reached");
}
}
}