MemberConditionAttribute 类

定义

根据一个或多个 staticBoolean 成员(属性、字段或无参数方法) Type 的值和成员名称,有条件地运行或忽略测试类或测试方法。

[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
继承
MemberConditionAttribute
属性

注解

向单个属性提供多个成员名称时,其值将与逻辑 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:测试仅在每个被引用成员的计算结果为true时运行。

MemberConditionAttribute(Type, String)

使用Include语义初始化类的新实例MemberConditionAttribute:仅当被引用成员的计算结果为true时,测试才会运行。

属性

名称 说明
ConditionMemberNames

获取针对此条件计算的成员( staticBoolean s)(属性、字段或无参数方法) ConditionType 的名称。 多个值与逻辑 AND 结合使用。

ConditionType

获取声明 static 用于计算条件的成员的类型。

GroupName

获取此属性的组名称。 当存在多个继承 ConditionBaseAttribute 属性时,这一点相关。 IsConditionMet同一组中属性值是“OR”在一起的。 不同组的值是“AND”一起。 换句话说,如果任何组的所有 IsConditionMet 值都为 false,将忽略测试。

IgnoreMessage

获取或设置忽略消息,该消息指示忽略测试方法或测试类的原因。

(继承自 ConditionBaseAttribute)
IsConditionMet

获取一个值,该值指示是否满足条件。 此属性的实现不应读取该 Mode 属性。

Mode

获取条件模式。

(继承自 ConditionBaseAttribute)

适用于