Table of Contents

Class XunitTestMethod

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

The default implementation of IXunitTestMethod for xUnit.net v3 based on MethodInfo.

public class XunitTestMethod : IXunitTestMethod, ITestMethod, ITestMethodMetadata, IXunitSerializable
Inheritance
XunitTestMethod
Implements
Inherited Members

Constructors

XunitTestMethod()

Called by the de-serializer; should only be called by deriving classes for de-serialization purposes

[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public XunitTestMethod()

XunitTestMethod(IXunitTestClass, MethodInfo, object?[], string?)

Initializes a new instance of the XunitTestMethod class.

public XunitTestMethod(IXunitTestClass testClass, MethodInfo method, object?[] testMethodArguments, string? uniqueID = null)

Parameters

testClass IXunitTestClass

The test class

method MethodInfo

The test method

testMethodArguments object[]

The arguments to pass to the test method

uniqueID string

The unique ID for the test method (only used to override default behavior in testing scenarios)

Properties

BeforeAfterTestAttributes

Gets the IBeforeAfterTestAttributes attached to the test method (and the test class, test collection, and test assembly).

public IReadOnlyCollection<IBeforeAfterTestAttribute> BeforeAfterTestAttributes { get; }

Property Value

IReadOnlyCollection<IBeforeAfterTestAttribute>

DataAttributes

Gets the IDataAttributes attached to the test method.

public IReadOnlyCollection<IDataAttribute> DataAttributes { get; }

Property Value

IReadOnlyCollection<IDataAttribute>

FactAttributes

Gets the IFactAttributes attached to the test method.

public IReadOnlyCollection<IFactAttribute> FactAttributes { get; }

Property Value

IReadOnlyCollection<IFactAttribute>

IsGenericMethodDefinition

Gets a flag which indicates whether this is a generic method definition.

public bool IsGenericMethodDefinition { get; }

Property Value

bool

Method

Gets the method that this test method refers to.

public MethodInfo Method { get; }

Property Value

MethodInfo

Remarks

This should only be used to execute a test method. All reflection should be abstracted here instead for better testability.

MethodName

Gets the name of the test method that is associated with this message.

public string MethodName { get; }

Property Value

string

Parameters

Gets the parameters of the test method.

public IReadOnlyCollection<ParameterInfo> Parameters { get; }

Property Value

IReadOnlyCollection<ParameterInfo>

ReturnType

Gets the return type of the test method.

public Type ReturnType { get; }

Property Value

Type

TestClass

Gets the test class that this test method belongs to.

public IXunitTestClass TestClass { get; }

Property Value

IXunitTestClass

TestMethodArguments

Gets the arguments that will be passed to the test method.

public object?[] TestMethodArguments { get; }

Property Value

object[]

Traits

Gets the trait values associated with this test method (and the test class, test collection, and test assembly). If there are none, or the framework does not support traits, this returns an empty dictionary (not null).

public IReadOnlyDictionary<string, IReadOnlyCollection<string>> Traits { get; }

Property Value

IReadOnlyDictionary<string, IReadOnlyCollection<string>>

UniqueID

Gets the unique ID for this test method.

public string UniqueID { get; }

Property Value

string

Remarks

The unique identifier for a test method should be able to discriminate among test methods in the same test assembly. This identifier should remain stable until such time as the developer changes some fundamental part of the identity (assembly, collection, test class, or test method). Recompilation of the test assembly is reasonable as a stability changing event.

Methods

Deserialize(IXunitSerializationInfo)

Called when the object should populate itself with data from the serialization info.

public void Deserialize(IXunitSerializationInfo info)

Parameters

info IXunitSerializationInfo

The info to get the object data from

GetDisplayName(string, object?[]?, Type[]?)

Gets the display name for the test method, factoring in arguments and generic types.

public string GetDisplayName(string baseDisplayName, object?[]? testMethodArguments, Type[]? methodGenericTypes)

Parameters

baseDisplayName string

The base display name.

testMethodArguments object[]

The test method arguments.

methodGenericTypes Type[]

The generic types of the method.

Returns

string

MakeGenericMethod(Type[])

Creates a generic version of the test method with the given generic types.

public MethodInfo MakeGenericMethod(Type[] genericTypes)

Parameters

genericTypes Type[]

The generic types

Returns

MethodInfo

ResolveGenericTypes(object?[])

Resolves the generic types for the test method given the method's arguments. If the method is not generic, will return null.

public Type[]? ResolveGenericTypes(object?[] arguments)

Parameters

arguments object[]

The method arguments

Returns

Type[]

ResolveMethodArguments(object?[])

Resolves argument values for the test method, ensuring they are the correct type, including support for optional method arguments.

public object?[] ResolveMethodArguments(object?[] arguments)

Parameters

arguments object[]

The test method arguments

Returns

object[]

Serialize(IXunitSerializationInfo)

Called when the object should store its serialized values into the serialization info.

public void Serialize(IXunitSerializationInfo info)

Parameters

info IXunitSerializationInfo

The info to store the object data into