Class TestCollectionRunner<TContext, TTestCollection, TTestClass, TTestCase>
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
TContextThe context type used by the runner
TTestCollectionThe type of the test collection used by the test framework. Must derive from ITestCollection.
TTestClassThe type of the test class used by the test framework. Must derive from ITestClass.
TTestCaseThe 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()
Initializes a new instance of the TestCollectionRunner<TContext, TTestCollection, TTestClass, TTestCase> class.
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
ctxtTContextThe context that describes the current test collection
testClassTTestClassThe test class that is being failed. May be
nullfor test cases that do not support classes and methods.testCasesIReadOnlyCollection<TTestCase>The test cases to be failed.
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.
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
ctxtTContextThe context that describes the current test collection
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.
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
ctxtTContextThe context that describes the current test collection
summaryRunSummaryThe execution summary for the test collection
Returns
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
ctxtTContextThe context that describes the current test collection
Returns
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
ctxtTContextThe 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
ctxtTContextThe context that describes the current test collection
testClassTTestClassThe test class to be run. May be
nullfor test cases that do not support classes and methods.testCasesIReadOnlyCollection<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
ctxtTContextThe context that describes the current test collection
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 collection and the given test collection status.
protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testCollectionStatus)
Parameters
ctxtTContextThe context that describes the current test collection
testCollectionStatusTestEngineStatusThe current test collection status.