Table of Contents

Class TestCaseRunnerBase<TContext, TTestCase>

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

A base class that provides default behavior when running test cases.

public abstract class TestCaseRunnerBase<TContext, TTestCase> where TContext : TestCaseRunnerBaseContext<TTestCase> where TTestCase : class, ITestCase

Type Parameters

TContext

The context type used by the runner

TTestCase

The type of the test case used by the test framework. Must derive from ITestCase.

Inheritance
TestCaseRunnerBase<TContext, TTestCase>
Derived
Inherited Members

Remarks

This class does not make any test-related assumptions about test cases, only that at some point, a test case will be "run" and results will be provided. As such, it has no definitions that related to tests (or ITest). The intention with this base class is that it can serve as a base for non-traditional test cases, such as injecting errors into the test pipeline during discovery that aren't uncovered until execution time.

Constructors

TestCaseRunnerBase()

Initializes a new instance of the TestCaseRunnerBase<TContext, TTestCase> class.

protected TestCaseRunnerBase()

Methods

OnTestCaseCleanupFailure(TContext, Exception)

This method is called when an exception was thrown while cleaning up, after the test case has run. By default, this sends TestCaseCleanupFailure.

protected virtual ValueTask<bool> OnTestCaseCleanupFailure(TContext ctxt, Exception exception)

Parameters

ctxt TContext

The context that describes the current test case

exception Exception

The exception that caused the cleanup failure (may be an instance of AggregateException if more than one exception occurred).

Returns

ValueTask<bool>

Return true if test execution should continue; false if it should be shut down.

Remarks

This method runs during CleaningUp and any exceptions thrown are converted into fatal exception messages (via IErrorMessage) and sent to the message bus in ctxt.

OnTestCaseFinished(TContext, RunSummary)

This method will be called when the test case has finished running. By default, this sends TestCaseFinished. Override this to enable any extensibility related to test case finish.

protected virtual ValueTask<bool> OnTestCaseFinished(TContext ctxt, RunSummary summary)

Parameters

ctxt TContext

The context that describes the current test case

summary RunSummary

The execution summary for the test case.

Returns

ValueTask<bool>

Return true if test execution should continue; false if it should be shut down.

Remarks

This method runs during CleaningUp and any exceptions thrown will contribute to test case cleanup failure.

OnTestCaseStarting(TContext)

This method will be called before the test case has started running. TBy default, this sends TestCaseStarting. Override this to enable any extensibility related to test case start.

protected virtual ValueTask<bool> OnTestCaseStarting(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test case

Returns

ValueTask<bool>

Return true if test execution should continue; false if it should be shut down.

Remarks

This method runs during Initializing and any exceptions thrown will contribute to test case failure (and will prevent the test case from running). Even if this method records exceptions, OnTestCaseFinished(TContext, RunSummary) will be called.

Run(TContext)

Executes the administrivia around running a test case, while leaving the actual test case execution up to RunTestCase(TContext, Exception?).

protected ValueTask<RunSummary> Run(TContext ctxt)

Parameters

ctxt TContext

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestCase(TContext, Exception?)

Override this to run the test case.

protected abstract ValueTask<RunSummary> RunTestCase(TContext ctxt, Exception? exception)

Parameters

ctxt TContext

The context that describes the current test case

exception Exception

The exception that was caused during startup; should be used as an indicator that the downstream tests should fail with the provided exception rather than going through standard execution

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

SetTestContext(TContext, TestEngineStatus)

Sets the current TestContext for the current test case and the given test case status.

protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testCaseStatus)

Parameters

ctxt TContext

The context that describes the current test case

testCaseStatus TestEngineStatus

The current test case status.

Remarks

This method must never throw. Behavior is undefined if it does. Instead, exceptions that occur should be recorded in the aggregator in ctxt and will be reflected in a way that's appropriate based on when this method is called.