NUnit Parallel Fixtures Conflict - Shared State Fails Under Parallelize
NUnit runs fixtures concurrently when [Parallelizable] (or an assembly-level LevelOfParallelism) is set. Tests that share static fields, a single database, or non-thread-safe setup then collide and fail only under parallel execution.
What this error means
Tests pass with parallelization off but fail intermittently with it on: one fixture mutates static/shared state another asserts on. The failing fixture changes as scheduling shifts - the hallmark of shared state under parallelism.
[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(4)]
// FAIL: Expected: 1 But was: 3
// two fixtures incremented the same static Counter concurrentlyCommon causes
Fixtures share static or global state
A static field, a shared singleton, or a single fixed database row is mutated by fixtures running in parallel, so an assertion observes another fixture’s change.
Non-thread-safe setup run concurrently
One-time setup that is not thread-safe (a shared file, a global config) executes from multiple workers at once and corrupts shared resources.
How to fix it
Isolate state or scope parallelism down
Give each fixture its own data, or mark conflicting fixtures non-parallel.
[TestFixture]
[NonParallelizable] // opt this fixture out
public class CounterTests { /* shares a static counter */ }
// elsewhere: give each fixture its own DB schema / temp dirMake shared resources per-fixture
- Use a unique database schema, temp directory, or account per fixture.
- Avoid mutable
staticstate in code under test. - Reproduce with parallelism on (not serial) to expose the collision.
How to prevent it
- Avoid mutable static state across fixtures.
- Provision per-fixture data instead of a shared fixed resource.
- Mark genuinely non-thread-safe fixtures
[NonParallelizable].