MemberConditionAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
[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
- 继承
- 属性
注解
向单个属性提供多个成员名称时,其值将与逻辑 AND 组合在一起:仅当每个引用的成员的计算结果为true时,该属性IsConditionMettrue的值才有效。
每个 MemberConditionAttribute 实例都有自己的实例 GroupName,因此在同一目标上堆叠多个 MemberConditionAttribute 声明与逻辑 AND 相结合,从而与其他测试框架中的典型 [ConditionalFact] 使用模式匹配。
如果找不到引用的成员作为publicstaticBoolean属性、字段或无参数方法,或者(对于方法)需要参数,则IsConditionMet计算将引发一个 。InvalidOperationException 此图面显示为测试错误,而不是无提示跳过,因此拼写错误和 refactors 不会意外禁用测试。
此属性不会继承。 将其应用于基类不会影响派生类。
[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() { }
构造函数
| 名称 | 说明 |
|---|---|
| MemberConditionAttribute(ConditionMode, Type, String, String[]) |
初始化 MemberConditionAttribute 类的新实例。 |
| MemberConditionAttribute(ConditionMode, Type, String) |
初始化 MemberConditionAttribute 类的新实例。 |
| MemberConditionAttribute(Type, String, String[]) |
使用Include语义初始化类的新实例MemberConditionAttribute:测试仅在每个被引用成员的计算结果为 |
| MemberConditionAttribute(Type, String) |
使用Include语义初始化类的新实例MemberConditionAttribute:仅当被引用成员的计算结果为 |
属性
| 名称 | 说明 |
|---|---|
| ConditionMemberNames |
获取针对此条件计算的成员( |
| ConditionType |
获取声明 |
| GroupName |
获取此属性的组名称。 当存在多个继承 ConditionBaseAttribute 属性时,这一点相关。 IsConditionMet同一组中属性值是“OR”在一起的。 不同组的值是“AND”一起。 换句话说,如果任何组的所有 IsConditionMet 值都为 false,将忽略测试。 |
| IgnoreMessage |
获取或设置忽略消息,该消息指示忽略测试方法或测试类的原因。 (继承自 ConditionBaseAttribute) |
| IsConditionMet |
获取一个值,该值指示是否满足条件。 此属性的实现不应读取该 Mode 属性。 |
| Mode |
获取条件模式。 (继承自 ConditionBaseAttribute) |