TestFilterProviderAttribute<TFilter> 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
強型別變體TestFilterProviderAttribute會TFilterITestFilter被 MSTest 介面卡在每次測試時所呼叫的實作。
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
[System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")]
public sealed class TestFilterProviderAttribute<TFilter> : Attribute where TFilter : ITestFilter, new()
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)>]
[<System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")>]
type TestFilterProviderAttribute<'Filter (requires 'Filter :> ITestFilter and 'Filter : (new : unit -> 'Filter))> = class
inherit Attribute
Public NotInheritable Class TestFilterProviderAttribute(Of TFilter)
Inherits Attribute
類型參數
- TFilter
實 ITestFilter 作是在消費測試組件中實例化並呼叫每個測試。
- 繼承
-
TestFilterProviderAttribute<TFilter>
- 屬性
範例
[assembly: TestFilterProvider<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;
}
備註
這是型別安全的形式。[assembly: TestFilterProvider(typeof(MyFilter))] 通用約束使編譯器在建置時強制執行非通用屬性只能在執行時驗證的條件: TFilter 必須實作 ITestFilter 並公開一個無參數建構子。
其他所有屬性的行為與 完全相同 TestFilterProviderAttribute,包括「每個測試組件最多一個」的規則——這兩個屬性被視為同一註冊,因此將兩者套用於單一組件是錯誤的。 它們是不同的類型,因此編譯器不會將該屬性報告為重複屬性; MSTEST0081 是的。
此屬性僅在針對 .NET 時可用。 在 .NET 框架中,使用非通用TestFilterProviderAttribute的 . 一個多目標的測試專案可以選擇合適的形式,且有:#if NET
#if NET
[assembly: TestFilterProvider<MyFilter>]
#else
[assembly: TestFilterProvider(typeof(MyFilter))]
#endif
建構函式
| 名稱 | Description |
|---|---|
| TestFilterProviderAttribute<TFilter>() |
強型別變體TestFilterProviderAttribute會 |