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 : BeforeAfterTestAttributeRemarks
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
BeforeAfterTestAttributeConditionalTestAttributeBase
Constructors
| Name | Description |
|---|---|
| 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.csInitializes a new instance of the ConditionalTestAttributeBase class.
protected ConditionalTestAttributeBase()ConditionalTestAttributeBase(TestGlobalizationMode)
ConditionalTestAttributeBase.csInitializes a new instance of the ConditionalTestAttributeBase class.
protected ConditionalTestAttributeBase(TestGlobalizationMode globalizationMode)Parameters
globalizationModeTestGlobalizationMode- The globalization mode the condition matches.
ConditionalTestAttributeBase(TestOperatingSystems)
ConditionalTestAttributeBase.csInitializes a new instance of the ConditionalTestAttributeBase class.
protected ConditionalTestAttributeBase(TestOperatingSystems operatingSystem)Parameters
operatingSystemTestOperatingSystems- The operating systems the condition matches.
ConditionalTestAttributeBase(TestOperatingSystems, TestGlobalizationMode)
ConditionalTestAttributeBase.csInitializes a new instance of the ConditionalTestAttributeBase class.
protected ConditionalTestAttributeBase(TestOperatingSystems operatingSystem, TestGlobalizationMode globalizationMode)Parameters
operatingSystemTestOperatingSystems- The operating systems the condition matches.
globalizationModeTestGlobalizationMode- The globalization mode the condition matches.
ConditionalTestAttributeBase(WindowsGroups)
ConditionalTestAttributeBase.csInitializes a new instance of the ConditionalTestAttributeBase class.
protected ConditionalTestAttributeBase(WindowsGroups windowsGroup)Parameters
windowsGroupWindowsGroups- The Windows group membership the condition matches.
Properties
| Name | Description |
|---|---|
| ContinuousIntegration | Gets or sets the continuous integration environments the condition matches. Defaults to ContinuousIntegrationEnvironments.None, which does not take part in the condition. |
| GlobalizationMode | Gets or sets the globalization mode the condition matches. Defaults to TestGlobalizationMode.Any, which does not take part in the condition. |
| InvertCondition | Gets a value indicating whether the test is skipped when the condition matches (true) or when it does not match (false). |
| OperatingSystem | Gets or sets the operating systems the condition matches. Defaults to TestOperatingSystems.None, which does not take part in the condition. |
| WindowsGroup | Gets or sets the Windows group membership the condition matches. Defaults to WindowsGroups.Any, which does not take part in the condition. |
ContinuousIntegration
ConditionalTestAttributeBase.csGets 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; }Property value
GlobalizationMode
ConditionalTestAttributeBase.csGets 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
InvertCondition
OperatingSystem
ConditionalTestAttributeBase.csGets 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
WindowsGroup
ConditionalTestAttributeBase.csGets 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
Methods
| Name | Description |
|---|---|
| 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.csEvaluates 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
methodUnderTestMethodInfo- The method under test.
testIXunitTest- The test that is about to run.