TestFilterProviderAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注册 MSTest 适配器针对要运行的每个测试调用的用户提供的 ITestFilter 实现,该实现将在应用任何命令行筛选器(--filter、测试资源管理器选择等)后运行。
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
public sealed class TestFilterProviderAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
[System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")]
[System.Runtime.CompilerServices.Nullable(0)]
public sealed class TestFilterProviderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)>]
type TestFilterProviderAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)>]
[<System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")>]
[<System.Runtime.CompilerServices.Nullable(0)>]
type TestFilterProviderAttribute = class
inherit Attribute
Public NotInheritable Class TestFilterProviderAttribute
Inherits Attribute
- 继承
-
TestFilterProviderAttribute
- 属性
示例
[assembly: TestFilterProvider(typeof(NightlyFilter))]
public sealed class NightlyFilter : ITestFilter
{
public TestFilterResult Filter(TestFilterContext context)
=> context.Categories.Contains("Nightly")
&& Environment.GetEnvironmentVariable("RUN_NIGHTLY") != "1"
? TestFilterResult.Skip("Set RUN_NIGHTLY=1 to run nightly tests.")
: TestFilterResult.Run;
}
注解
在测试程序集本身的程序集级别应用此属性。 最多可以应用一个 TestFilterProviderAttribute 测试程序集;这是有意的,因此筛选器排序不是公共 API 的一部分。 如果需要多个筛选策略,请在单个 ITestFilter 实现中显式编写它们。
筛选器类型必须是具有实现 ITestFilter的公共无参数构造函数的非泛型类。 每个测试运行的每个测试程序集创建一个实例,并重复使用该程序集的每个测试。
筛选器在加载测试类型之前、之前[AssemblyInitialize][ClassInitialize]和调用测试构造函数之前运行,因此删除或跳过测试ITestFilter可以避免支付上述任何费用。
构造函数
| 名称 | 说明 |
|---|---|
| TestFilterProviderAttribute(Type) |
初始化 TestFilterProviderAttribute 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| FilterType |
ITestFilter获取此属性注册的实现。 |