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

BeforeTestCommand

public abstract class BeforeTestCommand : DelegatingTestCommand
BeforeTestCommand is a DelegatingTestCommand that performs some specific action before the inner command is run.
using NUnit.Framework.Interfaces; using System; using System.Runtime.CompilerServices; namespace NUnit.Framework.Internal.Commands { [NullableContext(1)] [Nullable(0)] public abstract class BeforeTestCommand : DelegatingTestCommand { [Nullable(new byte[] { 2, 1 })] protected Action<TestExecutionContext> BeforeTest; public BeforeTestCommand(TestCommand innerCommand) : base(innerCommand) { } public override TestResult Execute(TestExecutionContext context) { Guard.OperationValid(BeforeTest != null, "BeforeTest was not set by the derived class constructor"); BeforeTest(context); TestStatus status = context.CurrentResult.ResultState.Status; if (status != TestStatus.Failed && status != TestStatus.Skipped) context.CurrentResult = innerCommand.Execute(context); return context.CurrentResult; } } }