Table of Contents

Class XunitTestFrameworkDiscoverer

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

The implementation of ITestFrameworkDiscoverer that supports discovery of unit tests linked against xunit.v3.core.dll.

public class XunitTestFrameworkDiscoverer : TestFrameworkDiscoverer<IXunitTestClass>, ITestFrameworkDiscoverer, IAsyncDisposable
Inheritance
XunitTestFrameworkDiscoverer
Implements
Inherited Members

Constructors

XunitTestFrameworkDiscoverer(IXunitTestAssembly, IXunitTestCollectionFactory?)

Initializes a new instance of the XunitTestFrameworkDiscoverer class.

public XunitTestFrameworkDiscoverer(IXunitTestAssembly testAssembly, IXunitTestCollectionFactory? collectionFactory = null)

Parameters

testAssembly IXunitTestAssembly

The test assembly

collectionFactory IXunitTestCollectionFactory

The test collection factory used to look up test collections.

Properties

DiscovererTypeCache

Gets the mapping dictionary of fact attribute type to discoverer type. The key is a type that implements IFactAttribute; the value is the discoverer type, if known; null if not.

protected Dictionary<Type, Type?> DiscovererTypeCache { get; }

Property Value

Dictionary<Type, Type>

TestAssembly

public IXunitTestAssembly TestAssembly { get; }

Property Value

IXunitTestAssembly

TestCollectionFactory

Gets the test collection factory that makes test collections.

public IXunitTestCollectionFactory TestCollectionFactory { get; }

Property Value

IXunitTestCollectionFactory

Methods

CreateTestClass(Type)

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

protected override ValueTask<IXunitTestClass> CreateTestClass(Type @class)

Parameters

class Type

The CLR type.

Returns

ValueTask<IXunitTestClass>

The test class.

Find(Func<ITestCase, ValueTask<bool>>, ITestFrameworkDiscoveryOptions, Type[]?, CancellationToken?)

Finds tests inside an assembly. Calls the callback for each discovered test.

public override 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

FindTestsForMethod(IXunitTestMethod, ITestFrameworkDiscoveryOptions, Func<ITestCase, ValueTask<bool>>)

Finds the tests on a test method.

protected virtual ValueTask<bool> FindTestsForMethod(IXunitTestMethod testMethod, ITestFrameworkDiscoveryOptions discoveryOptions, Func<ITestCase, ValueTask<bool>> discoveryCallback)

Parameters

testMethod IXunitTestMethod

The test method.

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.

Returns

ValueTask<bool>

Return true to continue test discovery, false, otherwise.

FindTestsForType(IXunitTestClass, ITestFrameworkDiscoveryOptions, Func<ITestCase, ValueTask<bool>>)

Core implementation to discover unit tests in a given test class.

protected override ValueTask<bool> FindTestsForType(IXunitTestClass testClass, ITestFrameworkDiscoveryOptions discoveryOptions, Func<ITestCase, ValueTask<bool>> discoveryCallback)

Parameters

testClass IXunitTestClass

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.

GetDiscoverer(Type)

Gets the test case discover instance for the given discoverer type. The instances are cached and reused, since they should not be stateful.

protected static IXunitTestCaseDiscoverer? GetDiscoverer(Type discovererType)

Parameters

discovererType Type

The discoverer type.

Returns

IXunitTestCaseDiscoverer

Returns the test case discoverer instance, if known; may return null when an error occurs (which is logged to the diagnostic message sink).

GetExportedTypes()

Override this to provide a list of the exported types in the assembly.

protected override Type[] GetExportedTypes()

Returns

Type[]