ConditionalTestAttributeBase Class

Base class for attributes that run or skip a test depending on the environment the test suite is running in.

public abstract class ConditionalTestAttributeBase : BeforeAfterTestAttribute

Remarks

Conditions are combined with a logical AND: the attribute matches only when every condition it defines matches.

Conditions are evaluated by ConditionalTestAttributeBase.Before, which xUnit calls after the test class instance has been created. Class fixtures, the test class constructor and IAsyncLifetime.InitializeAsync therefore run even when the test ends up being skipped.

Inheritance
BeforeAfterTestAttribute ConditionalTestAttributeBase

Constructors

NameDescription
ConditionalTestAttributeBase()Initializes a new instance of the ConditionalTestAttributeBase class.
ConditionalTestAttributeBase(TestGlobalizationMode)Initializes a new instance of the ConditionalTestAttributeBase class.
ConditionalTestAttributeBase(TestOperatingSystems)Initializes a new instance of the ConditionalTestAttributeBase class.
ConditionalTestAttributeBase(TestOperatingSystems, TestGlobalizationMode)Initializes a new instance of the ConditionalTestAttributeBase class.
ConditionalTestAttributeBase(WindowsGroups)Initializes a new instance of the ConditionalTestAttributeBase class.

ConditionalTestAttributeBase overloads

ConditionalTestAttributeBase()

ConditionalTestAttributeBase.cs

Initializes a new instance of the ConditionalTestAttributeBase class.

protected ConditionalTestAttributeBase()

ConditionalTestAttributeBase(TestGlobalizationMode)

ConditionalTestAttributeBase.cs

Initializes a new instance of the ConditionalTestAttributeBase class.

protected ConditionalTestAttributeBase(TestGlobalizationMode globalizationMode)
Parameters
globalizationMode TestGlobalizationMode
The globalization mode the condition matches.

ConditionalTestAttributeBase(TestOperatingSystems)

ConditionalTestAttributeBase.cs

Initializes a new instance of the ConditionalTestAttributeBase class.

protected ConditionalTestAttributeBase(TestOperatingSystems operatingSystem)
Parameters
operatingSystem TestOperatingSystems
The operating systems the condition matches.

ConditionalTestAttributeBase(TestOperatingSystems, TestGlobalizationMode)

ConditionalTestAttributeBase.cs

Initializes a new instance of the ConditionalTestAttributeBase class.

protected ConditionalTestAttributeBase(TestOperatingSystems operatingSystem, TestGlobalizationMode globalizationMode)
Parameters
operatingSystem TestOperatingSystems
The operating systems the condition matches.
globalizationMode TestGlobalizationMode
The globalization mode the condition matches.

ConditionalTestAttributeBase(WindowsGroups)

ConditionalTestAttributeBase.cs

Initializes a new instance of the ConditionalTestAttributeBase class.

protected ConditionalTestAttributeBase(WindowsGroups windowsGroup)
Parameters
windowsGroup WindowsGroups
The Windows group membership the condition matches.

Properties

NameDescription
ContinuousIntegrationGets or sets the continuous integration environments the condition matches. Defaults to ContinuousIntegrationEnvironments.None, which does not take part in the condition.
GlobalizationModeGets or sets the globalization mode the condition matches. Defaults to TestGlobalizationMode.Any, which does not take part in the condition.
InvertConditionGets a value indicating whether the test is skipped when the condition matches (true) or when it does not match (false).
OperatingSystemGets or sets the operating systems the condition matches. Defaults to TestOperatingSystems.None, which does not take part in the condition.
WindowsGroupGets or sets the Windows group membership the condition matches. Defaults to WindowsGroups.Any, which does not take part in the condition.

ContinuousIntegration

ConditionalTestAttributeBase.cs

Gets or sets the continuous integration environments the condition matches. Defaults to ContinuousIntegrationEnvironments.None, which does not take part in the condition.

public ContinuousIntegrationEnvironments ContinuousIntegration { get; set; }

Gets or sets the globalization mode the condition matches. Defaults to TestGlobalizationMode.Any, which does not take part in the condition.

public TestGlobalizationMode GlobalizationMode { get; set; }

Property value

TestGlobalizationMode

InvertCondition

Gets a value indicating whether the test is skipped when the condition matches (true) or when it does not match (false).

protected abstract bool InvertCondition { get; }

Property value

bool

Gets or sets the operating systems the condition matches. Defaults to TestOperatingSystems.None, which does not take part in the condition.

public TestOperatingSystems OperatingSystem { get; set; }

Property value

TestOperatingSystems

Gets or sets the Windows group membership the condition matches. Defaults to WindowsGroups.Any, which does not take part in the condition.

public WindowsGroups WindowsGroup { get; set; }

Property value

WindowsGroups

Methods

NameDescription
Before(MethodInfo, IXunitTest)Evaluates the condition and skips the test when it is not satisfied. Does nothing when the attribute defines no condition.

Before(MethodInfo, IXunitTest)

ConditionalTestAttributeBase.cs

Evaluates the condition and skips the test when it is not satisfied. Does nothing when the attribute defines no condition.

public override void Before(MethodInfo methodUnderTest, IXunitTest test)

Parameters

methodUnderTest MethodInfo
The method under test.
test IXunitTest
The test that is about to run.