Table of Contents

Class TestMethodRunner<TContext, TTestMethod, TTestCase>

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

A base class that provides default behavior when running tests in a test method.

public abstract class TestMethodRunner<TContext, TTestMethod, TTestCase> where TContext : TestMethodRunnerContext<TTestMethod, TTestCase> where TTestMethod : class, ITestMethod where TTestCase : class, ITestCase

Type Parameters

TContext

The context type used by the runner

TTestMethod

The type of the test method used by the test framework. Must derive from ITestMethod.

TTestCase

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

Inheritance
TestMethodRunner<TContext, TTestMethod, TTestCase>
Derived
Inherited Members

Constructors

TestMethodRunner()

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

protected TestMethodRunner()

Methods

FailTestCase(TContext, TTestCase, Exception)

Override this method to fail an individual test case.

protected virtual ValueTask<RunSummary> FailTestCase(TContext ctxt, TTestCase testCase, Exception exception)

Parameters

ctxt TContext

The context that describes the current test method

testCase TTestCase

The test case to be failed.

exception Exception

The exception that was caused during startup.

Returns

ValueTask<RunSummary>

Returns summary information about the test case run.

Remarks

By default, uses XunitRunnerHelper to fail the test cases.

OnTestMethodCleanupFailure(TContext, Exception)

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

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

Parameters

ctxt TContext

The context that describes the current test method

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.

OnTestMethodFinished(TContext, RunSummary)

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

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

Parameters

ctxt TContext

The context that describes the current test method

summary RunSummary

The execution summary for the test method

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 method cleanup failure.

OnTestMethodStarting(TContext)

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

protected virtual ValueTask<bool> OnTestMethodStarting(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test method

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 method failure (and will prevent the test method from running). Even if this method records exceptions, OnTestMethodFinished(TContext, RunSummary) will be called.

Run(TContext)

Runs the tests in the test method.

protected ValueTask<RunSummary> Run(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test method

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestCase(TContext, TTestCase)

Override this method to run an individual test case.

protected abstract ValueTask<RunSummary> RunTestCase(TContext ctxt, TTestCase testCase)

Parameters

ctxt TContext

The context that describes the current test method

testCase TTestCase

The test case to be run.

Returns

ValueTask<RunSummary>

Returns summary information about the test case run.

RunTestCases(TContext, Exception?)

Runs the list of test cases. By default, it runs the cases in order, synchronously.

protected virtual ValueTask<RunSummary> RunTestCases(TContext ctxt, Exception? exception)

Parameters

ctxt TContext

The context that describes the current test method

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 method and the given test method status.

protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testMethodStatus)

Parameters

ctxt TContext

The context that describes the current test method

testMethodStatus TestEngineStatus

The current test method 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.