Table of Contents

Class FactAttribute

Namespace
Xunit
Assembly
xunit.v3.core.dll

Attribute that is applied to a method to indicate that it is a fact that should be run by the default test runner.

[XunitTestCaseDiscoverer(typeof(FactDiscoverer))]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class FactAttribute : Attribute, IFactAttribute
Inheritance
FactAttribute
Implements
Derived
Inherited Members

Properties

DisplayName

Gets the name of the test to be used when the test is skipped. When null is returned, will cause a default display name to be used.

public string? DisplayName { get; set; }

Property Value

string

Explicit

Gets a flag which indicates whether the test should only be run explicitly. An explicit test is skipped by default unless explicit tests are requested to be run.

public bool Explicit { get; set; }

Property Value

bool

Skip

Gets the skip reason for the test. When null is returned, the test is not skipped.

public string? Skip { get; set; }

Property Value

string

Remarks

Skipping is conditional based on whether SkipWhen or SkipUnless is set.

SkipExceptions

Gets exceptions that, when thrown, will cause the test to be skipped rather than failed.

public Type[]? SkipExceptions { get; set; }

Property Value

Type[]

Remarks

The skip reason will be the exception's message.

SkipType

Gets the type to retrieve SkipUnless or SkipWhen from. If not set, then the property will be retrieved from the unit test class.

public Type? SkipType { get; set; }

Property Value

Type

SkipUnless

Gets the name of a public static property on the test class which returns bool to indicate whether the test should be skipped (false) or not (true).

public string? SkipUnless { get; set; }

Property Value

string

Remarks

This property cannot be set if SkipWhen is set. Setting both will result in a failed test. To ensure compile-time safety and easier refactoring, use the nameof operator, e.g., SkipUnless = nameof(IsConditionMet).

SkipWhen

Gets the name of a public static property on the test class which returns bool to indicate whether the test should be skipped (true) or not (false).

public string? SkipWhen { get; set; }

Property Value

string

Remarks

This property cannot be set if SkipUnless is set. Setting both will result in a failed test. To avoid issues during refactoring, it is recommended to use the nameof operator to reference the property, e.g., SkipWhen = nameof(IsTestSkipped).

Timeout

Gets the timeout for test (in milliseconds). When 0 is returned, the test will not have a timeout.

public int Timeout { get; set; }

Property Value

int

Remarks

WARNING: Using this with Aggressive will result in undefined behavior. Test timing and timeouts are only reliable when using Conservative (or when parallelization is disabled completely).