Class XunitTestMethod
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
testClassIXunitTestClassThe test class
methodMethodInfoThe test method
testMethodArgumentsobject[]The arguments to pass to the test method
uniqueIDstringThe 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
DataAttributes
Gets the IDataAttributes attached to the test method.
public IReadOnlyCollection<IDataAttribute> DataAttributes { get; }
Property Value
FactAttributes
Gets the IFactAttributes attached to the test method.
public IReadOnlyCollection<IFactAttribute> FactAttributes { get; }
Property Value
IsGenericMethodDefinition
Gets a flag which indicates whether this is a generic method definition.
public bool IsGenericMethodDefinition { get; }
Property Value
Method
Gets the method that this test method refers to.
public MethodInfo Method { get; }
Property Value
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
Parameters
Gets the parameters of the test method.
public IReadOnlyCollection<ParameterInfo> Parameters { get; }
Property Value
ReturnType
Gets the return type of the test method.
public Type ReturnType { get; }
Property Value
TestClass
Gets the test class that this test method belongs to.
public IXunitTestClass TestClass { get; }
Property Value
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
UniqueID
Gets the unique ID for this test method.
public string UniqueID { get; }
Property Value
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
infoIXunitSerializationInfoThe 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
baseDisplayNamestringThe base display name.
testMethodArgumentsobject[]The test method arguments.
methodGenericTypesType[]The generic types of the method.
Returns
MakeGenericMethod(Type[])
Creates a generic version of the test method with the given generic types.
public MethodInfo MakeGenericMethod(Type[] genericTypes)
Parameters
genericTypesType[]The generic types
Returns
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
argumentsobject[]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
argumentsobject[]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
infoIXunitSerializationInfoThe info to store the object data into