MemberConditionAttribute Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
public sealed class MemberConditionAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.ConditionBaseAttribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
[System.Runtime.CompilerServices.Nullable(0)]
public sealed class MemberConditionAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.ConditionBaseAttribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)>]
type MemberConditionAttribute = class
inherit ConditionBaseAttribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)>]
[<System.Runtime.CompilerServices.Nullable(0)>]
type MemberConditionAttribute = class
inherit ConditionBaseAttribute
Public NotInheritable Class MemberConditionAttribute
Inherits ConditionBaseAttribute
- Inheritance
- Attributes
Remarks
When multiple member names are supplied to a single attribute, their values are combined with a logical AND: the attribute's IsConditionMet is true only if every referenced member evaluates to true.
Each MemberConditionAttribute instance forms its own GroupName, so stacking multiple MemberConditionAttribute declarations on the same target is combined with a logical AND, matching the typical [ConditionalFact] usage pattern in other test frameworks.
If the referenced member cannot be found as a publicstaticBoolean property, field, or parameterless method, or (for methods) requires parameters, evaluating IsConditionMet throws an InvalidOperationException. This surfaces as a test error rather than a silent skip so typos and refactors don't accidentally disable tests.
This attribute isn't inherited. Applying it to a base class will not affect derived classes.
[TestMethod]
[MemberCondition(typeof(Environment), nameof(Environment.Is64BitProcess))]
public void Only_Runs_On_64Bit() { }
[TestMethod]
[MemberCondition(typeof(PlatformDetection),
nameof(PlatformDetection.IsNotBrowser),
nameof(PlatformDetection.IsThreadingSupported))]
public void Requires_Threading_And_Not_Browser() { }
[TestMethod]
[MemberCondition(ConditionMode.Exclude, typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime))]
public void Does_Not_Run_On_Mono() { }
Constructors
| Name | Description |
|---|---|
| MemberConditionAttribute(ConditionMode, Type, String, String[]) |
Initializes a new instance of the MemberConditionAttribute class. |
| MemberConditionAttribute(ConditionMode, Type, String) |
Initializes a new instance of the MemberConditionAttribute class. |
| MemberConditionAttribute(Type, String, String[]) |
Initializes a new instance of the MemberConditionAttribute class with
Include semantics: the test runs only when every referenced
member evaluates to |
| MemberConditionAttribute(Type, String) |
Initializes a new instance of the MemberConditionAttribute class with
Include semantics: the test runs only when the referenced
member evaluates to |
Properties
| Name | Description |
|---|---|
| ConditionMemberNames |
Gets the name(s) of the |
| ConditionType |
Gets the type declaring the |
| GroupName |
Gets the group name for this attribute. This is relevant when multiple attributes that inherit ConditionBaseAttribute are present. The IsConditionMet values of attributes in the same group are "OR"ed together. While the value from different groups is "AND"ed together. In other words, a test will be ignored if any group has all its IsConditionMet values as false. |
| IgnoreMessage |
Gets or sets the ignore message indicating the reason for ignoring the test method or test class. (Inherited from ConditionBaseAttribute) |
| IsConditionMet |
Gets a value indicating whether the condition is met. The implementation of this property shouldn't read the Mode property. |
| Mode |
Gets the condition mode. (Inherited from ConditionBaseAttribute) |