Table of Contents

Class XunitTestCase

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

Default implementation of IXunitTestCase for xUnit.net v3 that supports test methods decorated with FactAttribute. Test methods decorated with derived attributes may use this as a base class to build from.

public class XunitTestCase : IXunitTestCase, ITestCase, ITestCaseMetadata, IXunitSerializable, IAsyncDisposable
Inheritance
XunitTestCase
Implements
Derived
Inherited Members

Constructors

XunitTestCase()

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 XunitTestCase()

XunitTestCase(IXunitTestMethod, string, string, bool, Type[]?, string?, Type?, string?, string?, Dictionary<string, HashSet<string>>?, object?[]?, string?, int?, int?)

Initializes a new instance of the XunitTestCase class.

public XunitTestCase(IXunitTestMethod testMethod, string testCaseDisplayName, string uniqueID, bool @explicit, Type[]? skipExceptions = null, string? skipReason = null, Type? skipType = null, string? skipUnless = null, string? skipWhen = null, Dictionary<string, HashSet<string>>? traits = null, object?[]? testMethodArguments = null, string? sourceFilePath = null, int? sourceLineNumber = null, int? timeout = null)

Parameters

testMethod IXunitTestMethod

The test method this test case belongs to.

testCaseDisplayName string

The display name for the test case.

uniqueID string

The unique ID for the test case.

explicit bool

Indicates whether the test case was marked as explicit.

skipExceptions Type[]

The value obtained from SkipExceptions.

skipReason string

The value obtained from Skip.

skipType Type

The value obtained from SkipType.

skipUnless string

The value obtained from SkipUnless.

skipWhen string

The value obtained from SkipWhen.

traits Dictionary<string, HashSet<string>>

The optional traits list.

testMethodArguments object[]

The optional arguments for the test method.

sourceFilePath string

The optional source file in where this test case originated.

sourceLineNumber int?

The optional source line number where this test case originated.

timeout int?

The optional timeout for the test case (in milliseconds).

Properties

DisposalTracker

Used to dispose of test method arguments when the test case is disposed.

public DisposalTracker DisposalTracker { get; }

Property Value

DisposalTracker

Explicit

Gets a flag indicating whether this test case was marked as explicit or not.

public bool Explicit { get; }

Property Value

bool

SkipExceptions

Gets the exception types that, when thrown, will cause a

public Type[]? SkipExceptions { get; }

Property Value

Type[]

SkipReason

Gets the display text for the reason a test that might being skipped.

public string? SkipReason { get; protected set; }

Property Value

string

Remarks

This differs from the contract of SkipReason by virtue of the fact that when this value is non-null, it may indicate that a test is statically skipped (if both SkipUnless and SkipWhen are null) or dynamically skipped (if one is non-null).

SkipType

When set, indicates the type to use when resolving SkipUnless or SkipWhen. If not set, uses the test class type.

public Type? SkipType { get; protected set; }

Property Value

Type

SkipUnless

When set, indicates a public static property that is used at runtime to determine whether the test is skipped or not (true to run, false to skip).

public string? SkipUnless { get; protected set; }

Property Value

string

Remarks

Note: It is an error condition for both SkipUnless and SkipWhen to return a non-null value.

SkipWhen

When set, indicates a public static property that is used at runtime to determine whether the test is skipped or not (false to run, true to skip).

public string? SkipWhen { get; protected set; }

Property Value

string

Remarks

Note: It is an error condition for both SkipUnless and SkipWhen to return a non-null value.

SourceFilePath

Gets the source file name. A null value indicates that the source file name is not known.

public string? SourceFilePath { get; set; }

Property Value

string

SourceLineNumber

Gets the source file line number. A null value indicates that the source file line number is not known.

public int? SourceLineNumber { get; set; }

Property Value

int?

TestCaseDisplayName

Gets the display name of the test case.

public string TestCaseDisplayName { get; }

Property Value

string

TestClass

Gets the test class that this test case belongs to.

public IXunitTestClass TestClass { get; }

Property Value

IXunitTestClass

TestClassMetadataToken

Gets the MetadataToken for the test class.

public int TestClassMetadataToken { get; }

Property Value

int

TestClassName

Gets the full name of the class where the test is defined (i.e. FullName).

public string TestClassName { get; }

Property Value

string

TestClassNamespace

Gets the namespace of the class where the test is defined. If the test did not originate in a class, or the class it originated in does not reside in a namespace, will return null.

public string? TestClassNamespace { get; }

Property Value

string

TestClassSimpleName

Gets the simple name of the class where the test is defined (i.e. Name).

public string TestClassSimpleName { get; }

Property Value

string

TestCollection

Gets the test collection this test case belongs to.

public IXunitTestCollection TestCollection { get; }

Property Value

IXunitTestCollection

TestMethod

Gets the test method this test case belongs to.

public IXunitTestMethod TestMethod { get; }

Property Value

IXunitTestMethod

TestMethodArguments

public object?[] TestMethodArguments { get; }

Property Value

object[]

TestMethodMetadataToken

Gets the MetadataToken for the test method.

public int TestMethodMetadataToken { get; }

Property Value

int

TestMethodName

Gets the method name where the test is defined.

public string TestMethodName { get; }

Property Value

string

TestMethodParameterTypesVSTest

Gets the types for the test method parameters.

public string[] TestMethodParameterTypesVSTest { get; }

Property Value

string[]

Remarks

The values here are formatted according to VSTest rules in order to support Test Explorer. Note that this is not the same as FullName.

TestMethodReturnTypeVSTest

Gets the test method return type.

public string TestMethodReturnTypeVSTest { get; }

Property Value

string

Remarks

The value here is formatted according to VSTest rules in order to support Test Explorer. Note that this is not the same as FullName.

Timeout

Gets the timeout of the test, in milliseconds; if zero or negative, means the test case has no timeout.

public int Timeout { get; }

Property Value

int

Traits

Gets the traits associated with this test case.

public Dictionary<string, HashSet<string>> Traits { get; }

Property Value

Dictionary<string, HashSet<string>>

UniqueID

Gets a unique identifier for the test case.

public virtual string UniqueID { get; }

Property Value

string

Remarks

The unique identifier for a test case should be able to discriminate among test cases, even those which are varied invocations against the same test method (i.e., theories). This identifier should remain stable until such time as the developer changes some fundamental part of the identity (assembly, class name, test name, or test data). Recompilation of the test assembly is reasonable as a stability changing event.

Methods

CreateTests()

Creates the tests that are emitted from this test case. Exceptions thrown here will be caught and converted into a test case failure.

public virtual ValueTask<IReadOnlyCollection<IXunitTest>> CreateTests()

Returns

ValueTask<IReadOnlyCollection<IXunitTest>>

Remarks

By default, this method returns a single XunitTest that is appropriate for a one-to-one mapping between test and test case. Override this method to change the tests that are associated with this test case.

Deserialize(IXunitSerializationInfo)

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

protected virtual void Deserialize(IXunitSerializationInfo info)

Parameters

info IXunitSerializationInfo

The info to get the object data from

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public virtual ValueTask DisposeAsync()

Returns

ValueTask

PostInvoke()

Allows the test case to run some code just after the test case is finished running.

public virtual void PostInvoke()

PreInvoke()

Allows the test case to run some code just before the test case is run.

public virtual void PreInvoke()

ResolveTestMethodArguments(ParameterInfo[], object?[])

Computes values from the test case and resolves the test method arguments just before execution. Typically used from CreateTests() so that the executed test has an appropriately typed argument, regardless of the type that was used to serialize the argument.

protected static object?[] ResolveTestMethodArguments(ParameterInfo[] parameters, object?[] arguments)

Parameters

parameters ParameterInfo[]
arguments object[]

Returns

object[]

Serialize(IXunitSerializationInfo)

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

protected virtual void Serialize(IXunitSerializationInfo info)

Parameters

info IXunitSerializationInfo

The info to store the object data into