Class TestClassRunner<TContext, TTestClass, TTestMethod, TTestCase>
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
TContextThe context type used by the runner
TTestClassThe type of the test class used by the test framework. Must derive from ITestClass.
TTestMethodThe type of the test method used by the test framework. Must derive from ITestMethod.
TTestCaseThe 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
ctxtTContextThe context that describes the current test class
Returns
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
ctxtTContextThe context that describes the current test class
testMethodTTestMethodThe test method that contains the test cases. May be
nullfor test cases that do not support classes and methods.testCasesIReadOnlyCollection<TTestCase>The test cases to be failed.
constructorArgumentsobject[]The constructor arguments that would have been used to create the test class.
exceptionExceptionThe 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
ctxtTContextThe context that describes the current test class
exceptionExceptionThe exception that caused the cleanup failure (may be an instance of AggregateException if more than one exception occurred).
Returns
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
ctxtTContextThe context that describes the current test class
summaryRunSummaryThe execution summary for the test class
Returns
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
ctxtTContextThe context that describes the current test class
Returns
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
ctxtTContextThe 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
ctxtTContextThe 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
ctxtTContextThe context that describes the current test class
testMethodTTestMethodThe test method that contains the test cases. May be
nullfor test cases that do not support classes and methods.testCasesIReadOnlyCollection<TTestCase>The test cases to be run.
constructorArgumentsobject[]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
ctxtTContextThe context that describes the current test class
exceptionExceptionThe 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
ctxtTContextThe context that describes the current test class
testClassStatusTestEngineStatusThe 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.