Class XunitTestCase
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
testMethodIXunitTestMethodThe test method this test case belongs to.
testCaseDisplayNamestringThe display name for the test case.
uniqueIDstringThe unique ID for the test case.
explicitboolIndicates whether the test case was marked as explicit.
skipExceptionsType[]The value obtained from SkipExceptions.
skipReasonstringThe value obtained from Skip.
skipTypeTypeThe value obtained from SkipType.
skipUnlessstringThe value obtained from SkipUnless.
skipWhenstringThe value obtained from SkipWhen.
traitsDictionary<string, HashSet<string>>The optional traits list.
testMethodArgumentsobject[]The optional arguments for the test method.
sourceFilePathstringThe optional source file in where this test case originated.
sourceLineNumberint?The optional source line number where this test case originated.
timeoutint?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
Explicit
Gets a flag indicating whether this test case was marked as explicit or not.
public bool Explicit { get; }
Property Value
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
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
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
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
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
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
TestClass
Gets the test class that this test case belongs to.
public IXunitTestClass TestClass { get; }
Property Value
TestClassMetadataToken
Gets the MetadataToken for the test class.
public int TestClassMetadataToken { get; }
Property Value
TestClassName
Gets the full name of the class where the test is defined (i.e. FullName).
public string TestClassName { get; }
Property Value
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
TestClassSimpleName
Gets the simple name of the class where the test is defined (i.e. Name).
public string TestClassSimpleName { get; }
Property Value
TestCollection
Gets the test collection this test case belongs to.
public IXunitTestCollection TestCollection { get; }
Property Value
TestMethod
Gets the test method this test case belongs to.
public IXunitTestMethod TestMethod { get; }
Property Value
TestMethodArguments
public object?[] TestMethodArguments { get; }
Property Value
- object[]
TestMethodMetadataToken
Gets the MetadataToken for the test method.
public int TestMethodMetadataToken { get; }
Property Value
TestMethodName
Gets the method name where the test is defined.
public string TestMethodName { get; }
Property Value
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
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
Traits
Gets the traits associated with this test case.
public Dictionary<string, HashSet<string>> Traits { get; }
Property Value
UniqueID
Gets a unique identifier for the test case.
public virtual string UniqueID { get; }
Property Value
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
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
infoIXunitSerializationInfoThe 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
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
parametersParameterInfo[]argumentsobject[]
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
infoIXunitSerializationInfoThe info to store the object data into