Class TestCaseRunnerBase<TContext, TTestCase>
A base class that provides default behavior when running test cases.
public abstract class TestCaseRunnerBase<TContext, TTestCase> where TContext : TestCaseRunnerBaseContext<TTestCase> where TTestCase : class, ITestCase
Type Parameters
TContextThe context type used by the runner
TTestCaseThe type of the test case used by the test framework. Must derive from ITestCase.
- Inheritance
-
TestCaseRunnerBase<TContext, TTestCase>
- Derived
- Inherited Members
Remarks
This class does not make any test-related assumptions about test cases, only that at some point, a test case will be "run" and results will be provided. As such, it has no definitions that related to tests (or ITest). The intention with this base class is that it can serve as a base for non-traditional test cases, such as injecting errors into the test pipeline during discovery that aren't uncovered until execution time.
Constructors
TestCaseRunnerBase()
Initializes a new instance of the TestCaseRunnerBase<TContext, TTestCase> class.
protected TestCaseRunnerBase()
Methods
OnTestCaseCleanupFailure(TContext, Exception)
This method is called when an exception was thrown while cleaning up, after the test case has run. By default, this sends TestCaseCleanupFailure.
protected virtual ValueTask<bool> OnTestCaseCleanupFailure(TContext ctxt, Exception exception)
Parameters
ctxtTContextThe context that describes the current test case
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.
OnTestCaseFinished(TContext, RunSummary)
This method will be called when the test case has finished running. By default, this sends TestCaseFinished. Override this to enable any extensibility related to test case finish.
protected virtual ValueTask<bool> OnTestCaseFinished(TContext ctxt, RunSummary summary)
Parameters
ctxtTContextThe context that describes the current test case
summaryRunSummaryThe execution summary for the test case.
Returns
Remarks
This method runs during CleaningUp and any exceptions thrown will contribute to test case cleanup failure.
OnTestCaseStarting(TContext)
This method will be called before the test case has started running. TBy default, this sends TestCaseStarting. Override this to enable any extensibility related to test case start.
protected virtual ValueTask<bool> OnTestCaseStarting(TContext ctxt)
Parameters
ctxtTContextThe context that describes the current test case
Returns
Remarks
This method runs during Initializing and any exceptions thrown will contribute to test case failure (and will prevent the test case from running). Even if this method records exceptions, OnTestCaseFinished(TContext, RunSummary) will be called.
Run(TContext)
Executes the administrivia around running a test case, while leaving the actual test case execution up to RunTestCase(TContext, Exception?).
protected ValueTask<RunSummary> Run(TContext ctxt)
Parameters
ctxtTContext
Returns
- ValueTask<RunSummary>
Returns summary information about the tests that were run.
RunTestCase(TContext, Exception?)
Override this to run the test case.
protected abstract ValueTask<RunSummary> RunTestCase(TContext ctxt, Exception? exception)
Parameters
ctxtTContextThe context that describes the current test case
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 case and the given test case status.
protected virtual void SetTestContext(TContext ctxt, TestEngineStatus testCaseStatus)
Parameters
ctxtTContextThe context that describes the current test case
testCaseStatusTestEngineStatusThe current test case 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.