Table of Contents

Class TestAssemblyRunner<TContext, TTestAssembly, TTestCollection, TTestCase>

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

A base class that provides default behavior when running tests in an assembly. It groups the tests by test collection, and then runs the individual test collections.

public abstract class TestAssemblyRunner<TContext, TTestAssembly, TTestCollection, TTestCase> where TContext : TestAssemblyRunnerContext<TTestAssembly, TTestCase> where TTestAssembly : class, ITestAssembly where TTestCollection : class, ITestCollection where TTestCase : class, ITestCase

Type Parameters

TContext

The context type used by the runner

TTestAssembly

The type of the test assembly object model. Must derive from ITestAssembly.

TTestCollection

The type of the test collection object model. Must derive from ITestCollection.

TTestCase

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

Inheritance
TestAssemblyRunner<TContext, TTestAssembly, TTestCollection, TTestCase>
Derived
Inherited Members

Constructors

TestAssemblyRunner()

protected TestAssemblyRunner()

Methods

FailTestCollection(TContext, TTestCollection, IReadOnlyCollection<TTestCase>, Exception)

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

protected virtual ValueTask<RunSummary> FailTestCollection(TContext ctxt, TTestCollection testCollection, IReadOnlyCollection<TTestCase> testCases, Exception exception)

Parameters

ctxt TContext

The context that describes the current test assembly

testCollection TTestCollection

The test collection that is being failed.

testCases IReadOnlyCollection<TTestCase>

The test cases that belong to the test collection.

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.

GetTestFrameworkDisplayName(TContext)

Gets the display name for the test framework. Used to populate TestAssemblyStarting during OnTestAssemblyStarting(TContext).

protected abstract ValueTask<string> GetTestFrameworkDisplayName(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test assembly

Returns

ValueTask<string>

OnTestAssemblyCleanupFailure(TContext, Exception)

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

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

Parameters

ctxt TContext

The context that describes the current test assembly

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.

OnTestAssemblyFinished(TContext, RunSummary)

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

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

Parameters

ctxt TContext

The context that describes the current test assembly

summary RunSummary

The execution summary for the test assembly

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

OnTestAssemblyStarting(TContext)

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

protected virtual ValueTask<bool> OnTestAssemblyStarting(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test assembly

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

OrderTestCollections(TContext)

Orders the test collections in the assembly. By default does not re-order the test collections. Override this to provide custom test collection ordering.

protected virtual List<(TTestCollection Collection, List<TTestCase> TestCases)> OrderTestCollections(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test assembly

Returns

List<(TTestCollection Collection, List<TTestCase> TestCases)>

Test collections in run order (and associated, not-yet-ordered test cases).

Run(TContext)

Runs the tests in the test assembly.

protected ValueTask<RunSummary> Run(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test assembly

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestCollection(TContext, TTestCollection, IReadOnlyCollection<TTestCase>)

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

protected abstract ValueTask<RunSummary> RunTestCollection(TContext ctxt, TTestCollection testCollection, IReadOnlyCollection<TTestCase> testCases)

Parameters

ctxt TContext

The context that describes the current test assembly

testCollection TTestCollection

The test collection that is being run.

testCases IReadOnlyCollection<TTestCase>

The test cases that belong to the test collection.

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestCollections(TContext, Exception?)

Runs the list of test collections. By default, groups the tests by collection and runs them synchronously.

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

Parameters

ctxt TContext

The context that describes the current test assembly

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

protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testAssemblyStatus)

Parameters

ctxt TContext

The context that describes the current test assembly

testAssemblyStatus TestEngineStatus

The current test assembly status.