Table of Contents

Class TestFrameworkDiscoverer<TTestClass>

Namespace
Xunit.v3
Assembly
xunit.v3.core.dll

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

TTestClass

The 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

testAssembly ITestAssembly

Properties

DisposalTracker

Gets the disposal tracker for the test framework discoverer.

protected DisposalTracker DisposalTracker { get; }

Property Value

DisposalTracker

TestAssembly

Gets the test assembly.

public ITestAssembly TestAssembly { get; }

Property Value

ITestAssembly

Methods

CreateTestClass(Type)

Implement this method to create a test class for the given CLR type.

protected abstract ValueTask<TTestClass> CreateTestClass(Type @class)

Parameters

class Type

The 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

ValueTask

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

callback Func<ITestCase, ValueTask<bool>>

Called for each discovered test. Return true to continue test discovery; return false to cancel test discovery.

discoveryOptions ITestFrameworkDiscoveryOptions

The options used by the test framework during discovery.

types Type[]

When passed a non-null collection, only returns tests found from one of the provided types; when passed a null collection, discovers all tests in the assembly.

cancellationToken CancellationToken?

The optional cancellation token which can be used to cancel the test discovery process.

Returns

ValueTask

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

testClass TTestClass

The test class.

discoveryOptions ITestFrameworkDiscoveryOptions

The options used by the test framework during discovery.

discoveryCallback Func<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 true to continue discovery, or false to halt it.

Returns

ValueTask<bool>

Returns true if discovery should continue; false otherwise.

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

type Type

The type.

Returns

bool

Returns true if the type can contain tests; false, otherwise.