Search code examples
nunit

NUnit Run OneTimeSetUps after OneTimeTearDowns of other tests


How do I organize tests so that their OneTimeSetUps are run after OneTimeTearDowns of others is done? The tests need conflicting setups, but all OneTimeSetUps are run first thing, so this doesn't work.

I made a small setup. Foo and Bar, with their respective OneTimes, are in different namespaces in different classes each tagged with [TestFixture]. This is the order things are run:

FooOneTimeSetUp
BarOneTimeSetUp
Foo
FooOneTimeTearDown
Bar
BarOneTimeTearDown

Solution

  • Turns out what I want is default behavior. However, the project I was working on had set [assembly: Parallelizable(ParallelScope.Children)], which causes the unwanted behavior in my question, even though [assembly: LevelOfParallelism(1)] was also set and enforced similarly by the runners.

    This is explained in the docs here: https://docs.nunit.org/articles/nunit/technical-notes/usage/Framework-Parallel-Test-Execution.html