Table of Contents

Class TestRunnerBase<TContext, TTest>

Namespace
Xunit.v3
Assembly
xunit.v3.core.dll

A base class that provides default behavior when running a test. This includes support for skipping tests.

public abstract class TestRunnerBase<TContext, TTest> where TContext : TestRunnerBaseContext<TTest> where TTest : class, ITest

Type Parameters

TContext

The context type used by the runner

TTest

The test type used by the test framework. Must derive from ITest.

Inheritance
TestRunnerBase<TContext, TTest>
Derived
TestRunner<TContext, TTest>
Inherited Members

Remarks

This class does not make any assumptions about what it means to run an individual test, just that at some point, the test will be run. The intention with this base class is that it can serve as a base for non-traditional tests (e.g., tests that are not derived from invoking CLR methods).

Constructors

TestRunnerBase()

Initializes a new instance of the TestRunner<TContext, TTest> class.

Methods

GetTestOutput(TContext)

Gets any output collected from the test after execution is complete. If the test framework did not collect any output, or does not support collecting output, then it should return Empty.

GetWarnings(TContext)

Gets the warnings that will be reported during test results. By default, returns null, indicating that there were no warnings

OnTestCleanupFailure(TContext, Exception)

This method is called when an exception was thrown while cleaning up, after the test has run. By default, this sends (like TestCleanupFailure).

OnTestFailed(TContext, Exception, decimal, string, string[]?)

This method is called when a test has failed. By default, this sends TestFailed.

OnTestFinished(TContext, decimal, string, string[]?)

This method is called just after the test has finished running. By default, this sends TestFinished. Override this to enable any extensibility related to test finish.

OnTestNotRun(TContext, string, string[]?)

This method is called when a test was not run. By default, this sends TestNotRun.

OnTestPassed(TContext, decimal, string, string[]?)

This method is called when a test has passed. By default, this sends TestPassed.

OnTestSkipped(TContext, string, decimal, string, string[]?)

This method is called when a test is skipped. By default, this sends TestSkipped.

OnTestStarting(TContext)

This method is called just before the test is run. By default, this sends TestStarting. Override this to enable any extensibility related to test start.

OnTestStarting(TContext, bool, int)

This is a helper that allows passing explicit and timeout values, since those are not part of the core object model.

Run(TContext)

Runs the test.

RunTest(TContext)

Override this method to run the test.

SetTestContext(TContext, TestEngineStatus, TestResultState?, object?)

Sets the test context for the given test state and engine status.

ShouldTestRun(TContext)

Override this to determine whether a test should be run or not (meaning, if you return false, it will be reported with a status of NotRun). By default, this method will return true. This is typically used to implement the ability to exclude specific tests unless they've been explicitly asked to be run.

UpdateTestContext(object?, TestResultState?)

Updates the test context values while the test is running, without swapping out the test context itself. This preserves the values in the existing context (notably, the cancellation token, which is wrapped and passed, and as such cannot be replaced).