Table of Contents

Class XunitTestRunnerBase<TContext, TTest>

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

The base test runner for xUnit.net v3 tests (with overridable context).

public class XunitTestRunnerBase<TContext, TTest> : TestRunner<TContext, TTest> where TContext : XunitTestRunnerBaseContext<TTest> where TTest : class, IXunitTest

Type Parameters

TContext
TTest
Inheritance
TestRunnerBase<TContext, TTest>
TestRunner<TContext, TTest>
XunitTestRunnerBase<TContext, TTest>
Derived
Inherited Members

Methods

CreateTestClassInstance(TContext)

Override to creates and initialize the instance of the test class.

protected override ValueTask<(object? Instance, SynchronizationContext? SyncContext, ExecutionContext? ExecutionContext)> CreateTestClassInstance(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

Returns

ValueTask<(object Instance, SynchronizationContext SyncContext, ExecutionContext ExecutionContext)>

Returns the test class instance, the sync context that is current after the creation, and a capture of the execution context so that it can be restored later.

Remarks

This method runs during Running and any exceptions thrown will contribute to test failure. Since the method is potentially async, we depend on it to capture and return the sync context so that it may be propagated appropriately.

GetAttachments(TContext)

Gets the attachments for the test. If the test framework did not collect attachments (or does not support attachments), then it should return null.

protected override ValueTask<IReadOnlyDictionary<string, TestAttachment>?> GetAttachments(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

Returns

ValueTask<IReadOnlyDictionary<string, TestAttachment>>

Remarks

By default, this method returns Attachments from the current context. This method runs during Running and any exceptions thrown will contribute to test failure.

GetTestOutput(TContext)

Gets any output collected from the test after execution is complete. If the test framework did not collect any output, or does not support collecting output, then it should return Empty.

protected override ValueTask<string> GetTestOutput(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

Returns

ValueTask<string>

Remarks

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

GetWarnings(TContext)

Gets the warnings that will be reported during test results. By default, returns null, indicating that there were no warnings

protected override ValueTask<string[]?> GetWarnings(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

Returns

ValueTask<string[]>

Remarks

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

InvokeTest(TContext, object?)

Invokes the test method and returns the amount of time spent executing.

protected override ValueTask<TimeSpan> InvokeTest(TContext ctxt, object? testClassInstance)

Parameters

ctxt TContext

The context that describes the current test

testClassInstance object

The instance of the test class (may be null when running a static test method)

Returns

ValueTask<TimeSpan>

Returns the execution time (in seconds) spent running the test method.

Remarks

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

IsTestClassCreatable(TContext)

Override to determine whether a test class should be created.

protected override bool IsTestClassCreatable(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

Returns

bool

Remarks

This method runs during Running and any exceptions thrown will contribute to test failure (and test class creation will not take place).

OnTestStarting(TContext)

This method is called just before the test is run. By default, this sends TestStarting. Override this to enable any extensibility related to test start.

protected override ValueTask<bool> OnTestStarting(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

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 failure (and will prevent the test from running). Even if this method records exceptions, OnTestFinished(TContext, decimal, string, string[]?, IReadOnlyDictionary<string, TestAttachment>?) will be called.

PostInvoke(TContext)

Override this method to call code just after the test invocation has completed, but before the test class instance has been disposed.

protected override void PostInvoke(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

PreInvoke(TContext)

Override this method to call code just after the test class instance has been created, but before the test has been invoked.

protected override void PreInvoke(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

RunTest(TContext)

Override this method to run the test.

protected override ValueTask<TimeSpan> RunTest(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

Returns

ValueTask<TimeSpan>

ShouldTestRun(TContext)

Override this to determine whether a test should be run or not (meaning, if you return false, it will be reported with a status of NotRun). By default, this method will return true. This is typically used to implement the ability to exclude specific tests unless they've been explicitly asked to be run.

protected override bool ShouldTestRun(TContext ctxt)

Parameters

ctxt TContext

The context that describes the current test

Returns

bool

Remarks

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