Class TestAssemblyRunner<TContext, TTestAssembly, TTestCollection, TTestCase>
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
TContextThe context type used by the runner
TTestAssemblyThe type of the test assembly object model. Must derive from ITestAssembly.
TTestCollectionThe type of the test collection object model. Must derive from ITestCollection.
TTestCaseThe 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()
Initializes a new instance of the TestAssemblyRunner<TContext, TTestAssembly, TTestCollection, TTestCase> class.
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
ctxtTContextThe context that describes the current test assembly
testCollectionTTestCollectionThe test collection that is being failed.
testCasesIReadOnlyCollection<TTestCase>The test cases that belong to the test collection.
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.
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
ctxtTContextThe context that describes the current test assembly
Returns
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
ctxtTContextThe context that describes the current test assembly
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.
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
ctxtTContextThe context that describes the current test assembly
summaryRunSummaryThe execution summary for the test assembly
Returns
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
ctxtTContextThe context that describes the current test assembly
Returns
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
ctxtTContextThe 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
ctxtTContextThe 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
ctxtTContextThe context that describes the current test assembly
testCollectionTTestCollectionThe test collection that is being run.
testCasesIReadOnlyCollection<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
ctxtTContextThe context that describes the current test assembly
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 assembly and the given test assembly status.
protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testAssemblyStatus)
Parameters
ctxtTContextThe context that describes the current test assembly
testAssemblyStatusTestEngineStatusThe current test assembly status.