Class TestFrameworkDiscoverer<TTestClass>
A base implementation of ITestFrameworkDiscoverer that supports test filtering and runs the discovery process on a thread pool thread.
public abstract class TestFrameworkDiscoverer<TTestClass> : ITestFrameworkDiscoverer, IAsyncDisposable where TTestClass : class, ITestClass
Type Parameters
TTestClassThe test class object model type. Must derive from ITestClass.
- Inheritance
-
TestFrameworkDiscoverer<TTestClass>
- Implements
- Derived
- Inherited Members
Constructors
TestFrameworkDiscoverer(ITestAssembly)
A base implementation of ITestFrameworkDiscoverer that supports test filtering and runs the discovery process on a thread pool thread.
protected TestFrameworkDiscoverer(ITestAssembly testAssembly)
Parameters
testAssemblyITestAssembly
Properties
DisposalTracker
Gets the disposal tracker for the test framework discoverer.
protected DisposalTracker DisposalTracker { get; }
Property Value
TestAssembly
Gets the test assembly.
public ITestAssembly TestAssembly { get; }
Property Value
Methods
CreateTestClass(Type)
Implement this method to create a test class for the given CLR type.
protected abstract ValueTask<TTestClass> CreateTestClass(Type @class)
Parameters
classTypeThe CLR type.
Returns
- ValueTask<TTestClass>
The test class.
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public virtual ValueTask DisposeAsync()
Returns
Find(Func<ITestCase, ValueTask<bool>>, ITestFrameworkDiscoveryOptions, Type[]?, CancellationToken?)
Finds tests inside an assembly. Calls the callback for each discovered test.
public virtual ValueTask Find(Func<ITestCase, ValueTask<bool>> callback, ITestFrameworkDiscoveryOptions discoveryOptions, Type[]? types = null, CancellationToken? cancellationToken = null)
Parameters
callbackFunc<ITestCase, ValueTask<bool>>Called for each discovered test. Return
trueto continue test discovery; returnfalseto cancel test discovery.discoveryOptionsITestFrameworkDiscoveryOptionsThe options used by the test framework during discovery.
typesType[]When passed a non-
nullcollection, only returns tests found from one of the provided types; when passed anullcollection, discovers all tests in the assembly.cancellationTokenCancellationToken?The optional cancellation token which can be used to cancel the test discovery process.
Returns
FindTestsForType(TTestClass, ITestFrameworkDiscoveryOptions, Func<ITestCase, ValueTask<bool>>)
Core implementation to discover unit tests in a given test class.
protected abstract ValueTask<bool> FindTestsForType(TTestClass testClass, ITestFrameworkDiscoveryOptions discoveryOptions, Func<ITestCase, ValueTask<bool>> discoveryCallback)
Parameters
testClassTTestClassThe test class.
discoveryOptionsITestFrameworkDiscoveryOptionsThe options used by the test framework during discovery.
discoveryCallbackFunc<ITestCase, ValueTask<bool>>The callback that is called for each discovered test case. The return value of the callback indicates the same thing as the return value of this function: return
trueto continue discovery, orfalseto halt it.
Returns
GetExportedTypes()
Override this to provide a list of the exported types in the assembly.
protected abstract Type[] GetExportedTypes()
Returns
- Type[]
IsValidTestClass(Type)
Determines if a type should be used for discovery. Can be used to filter out types that are not desirable. The default implementation filters out abstract (non-static) classes.
protected virtual bool IsValidTestClass(Type type)
Parameters
typeTypeThe type.
Returns
- bool
Returns
trueif the type can contain tests;false, otherwise.