<PackageReference Include="NUnit" Version="3.0.0-alpha-3" />

SetUpTearDownItem

public class SetUpTearDownItem
SetUpTearDownItem holds the setup and teardown methods for a single level of the inheritance hierarchy.
using System; using System.Collections.Generic; using System.Reflection; namespace NUnit.Framework.Internal.Commands { public class SetUpTearDownItem { private IList<MethodInfo> _setUpMethods; private IList<MethodInfo> _tearDownMethods; private bool _setUpWasRun; public bool HasMethods { get { if (_setUpMethods.Count <= 0) return _tearDownMethods.Count > 0; return true; } } public SetUpTearDownItem(IList<MethodInfo> setUpMethods, IList<MethodInfo> tearDownMethods) { _setUpMethods = setUpMethods; _tearDownMethods = tearDownMethods; } public void RunSetUp(TestExecutionContext context) { _setUpWasRun = true; foreach (MethodInfo setUpMethod in _setUpMethods) { Reflect.InvokeMethod(setUpMethod, setUpMethod.IsStatic ? null : context.TestObject); } } public void RunTearDown(TestExecutionContext context) { if (_setUpWasRun) try { int num = _tearDownMethods.Count; while (--num >= 0) { Reflect.InvokeMethod(_tearDownMethods[num], _tearDownMethods[num].IsStatic ? null : context.TestObject); } } catch (Exception ex) { context.CurrentResult.RecordTearDownException(ex); } } } }