<PackageReference Include="NUnit" Version="3.8.0" />

SetUpFixtureAttribute

Attribute used to identify a class that contains OneTimeSetUpAttribute or OneTimeTearDownAttribute methods for all the test fixtures under a given namespace.
using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; namespace NUnit.Framework { [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] public class SetUpFixtureAttribute : NUnitAttribute, IFixtureBuilder { public IEnumerable<TestSuite> BuildFrom(ITypeInfo typeInfo) { SetUpFixture setUpFixture = new SetUpFixture(typeInfo); if (setUpFixture.RunState != 0) { string reason = null; if (!IsValidFixtureType(typeInfo, ref reason)) setUpFixture.MakeInvalid(reason); } return new TestSuite[1] { setUpFixture }; } private bool IsValidFixtureType(ITypeInfo typeInfo, ref string reason) { if (typeInfo.IsAbstract) { reason = $"{typeInfo.FullName}"""; return false; } if (!typeInfo.HasConstructor(new Type[0])) { reason = $"{typeInfo.FullName}"""; return false; } Type[] array = new Type[2] { typeof(SetUpAttribute), typeof(TearDownAttribute) }; foreach (Type type in array) { if (typeInfo.HasMethodWithAttribute(type)) { reason = type.Name + " attribute not allowed in a SetUpFixture"; return false; } } return true; } } }