Table of Contents

Class TestClassRunner<TContext, TTestClass, TTestMethod, TTestCase>

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

A base class that provides default behavior when running tests in a test class. It groups the tests by test method, and then runs the individual test methods.

public abstract class TestClassRunner<TContext, TTestClass, TTestMethod, TTestCase> where TContext : TestClassRunnerContext<TTestClass, TTestCase> where TTestClass : class, ITestClass where TTestMethod : class, ITestMethod where TTestCase : class, ITestCase

Type Parameters

TContext

The context type used by the runner

TTestClass

The type of the test class used by the test framework. Must derive from ITestClass.

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
TestClassRunner<TContext, TTestClass, TTestMethod, TTestCase>
Derived
Inherited Members

Constructors

TestClassRunner()

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

protected TestClassRunner()

Methods

CreateTestClassConstructorArguments(TContext)

Creates the arguments for the test class constructor. By default just returns an empty set of arguments. Override to find the arguments for the constructor.

protected virtual ValueTask<object?[]> CreateTestClassConstructorArguments(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test class

Returns

ValueTask<object[]>

The test class constructor arguments.

Remarks

This method runs during Initializing and any exceptions thrown will contribute to test class failure (and will prevent the test class from running)

FailTestMethod(TContext, TTestMethod?, IReadOnlyCollection<TTestCase>, object?[], Exception)

Fails the tests from a test method due to an exception.

protected virtual ValueTask<RunSummary> FailTestMethod(TContext ctxt, TTestMethod? testMethod, IReadOnlyCollection<TTestCase> testCases, object?[] constructorArguments, Exception exception)

Parameters

ctxt TContext

The context that describes the current test class

testMethod TTestMethod

The test method that contains the test cases. May be null for test cases that do not support classes and methods.

testCases IReadOnlyCollection<TTestCase>

The test cases to be failed.

constructorArguments object[]

The constructor arguments that would have been used to create the test class.

exception Exception

The exception that was caused during startup.

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were failed.

Remarks

By default, using XunitRunnerHelper to fail the test cases.

OnTestClassCleanupFailure(TContext, Exception)

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

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

Parameters

ctxt TContext

The context that describes the current test class

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.

OnTestClassFinished(TContext, RunSummary)

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

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

Parameters

ctxt TContext

The context that describes the current test class

summary RunSummary

The execution summary for the test class

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

OnTestClassStarting(TContext)

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

protected virtual ValueTask<bool> OnTestClassStarting(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test class

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

OrderTestCases(TContext)

Orders the test cases in the class. By default does not re-order the test cases. Override this to provide custom test case ordering.

protected virtual IReadOnlyCollection<TTestCase> OrderTestCases(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test class

Returns

IReadOnlyCollection<TTestCase>

Remarks

This method runs during Running and any exceptions thrown will contribute to test class failure

Run(TContext)

Runs the tests in the test class.

protected ValueTask<RunSummary> Run(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test class

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestMethod(TContext, TTestMethod?, IReadOnlyCollection<TTestCase>, object?[])

Override this method to run the tests in an individual test method.

protected abstract ValueTask<RunSummary> RunTestMethod(TContext ctxt, TTestMethod? testMethod, IReadOnlyCollection<TTestCase> testCases, object?[] constructorArguments)

Parameters

ctxt TContext

The context that describes the current test class

testMethod TTestMethod

The test method that contains the test cases. May be null for test cases that do not support classes and methods.

testCases IReadOnlyCollection<TTestCase>

The test cases to be run.

constructorArguments object[]

The constructor arguments that will be used to create the test class.

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestMethods(TContext, Exception?)

Runs the list of test methods. By default, orders the tests, groups them by method and runs them synchronously.

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

Parameters

ctxt TContext

The context that describes the current test class

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

protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testClassStatus)

Parameters

ctxt TContext

The context that describes the current test class

testClassStatus TestEngineStatus

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