Table of Contents

Class TestCollectionRunner<TContext, TTestCollection, TTestClass, TTestCase>

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

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

public abstract class TestCollectionRunner<TContext, TTestCollection, TTestClass, TTestCase> where TContext : TestCollectionRunnerContext<TTestCollection, TTestCase> where TTestCollection : class, ITestCollection where TTestClass : class, ITestClass where TTestCase : class, ITestCase

Type Parameters

TContext

The context type used by the runner

TTestCollection

The type of the test collection used by the test framework. Must derive from ITestCollection.

TTestClass

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

TTestCase

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

Inheritance
TestCollectionRunner<TContext, TTestCollection, TTestClass, TTestCase>
Derived
Inherited Members

Constructors

TestCollectionRunner()

protected TestCollectionRunner()

Methods

FailTestClass(TContext, TTestClass?, IReadOnlyCollection<TTestCase>, Exception)

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

protected virtual ValueTask<RunSummary> FailTestClass(TContext ctxt, TTestClass? testClass, IReadOnlyCollection<TTestCase> testCases, Exception exception)

Parameters

ctxt TContext

The context that describes the current test collection

testClass TTestClass

The test class that is being failed. May be null for test cases that do not support classes and methods.

testCases IReadOnlyCollection<TTestCase>

The test cases to be failed.

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.

OnTestCollectionCleanupFailure(TContext, Exception)

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

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

Parameters

ctxt TContext

The context that describes the current test collection

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.

OnTestCollectionFinished(TContext, RunSummary)

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

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

Parameters

ctxt TContext

The context that describes the current test collection

summary RunSummary

The execution summary for the test collection

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

OnTestCollectionStarting(TContext)

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

protected virtual ValueTask<bool> OnTestCollectionStarting(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test collection

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

Run(TContext)

Runs the tests in the test collection.

protected ValueTask<RunSummary> Run(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test collection

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestClass(TContext, TTestClass?, IReadOnlyCollection<TTestCase>)

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

protected abstract ValueTask<RunSummary> RunTestClass(TContext ctxt, TTestClass? testClass, IReadOnlyCollection<TTestCase> testCases)

Parameters

ctxt TContext

The context that describes the current test collection

testClass TTestClass

The test class to be run. May be null for test cases that do not support classes and methods.

testCases IReadOnlyCollection<TTestCase>

The test cases to be run.

Returns

ValueTask<RunSummary>

Returns summary information about the tests that were run.

RunTestClasses(TContext, Exception?)

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

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

Parameters

ctxt TContext

The context that describes the current test collection

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

protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testCollectionStatus)

Parameters

ctxt TContext

The context that describes the current test collection

testCollectionStatus TestEngineStatus

The current test collection status.