Language

TestFilterProviderAttribute<TFilter> クラス

定義

MSTest アダプターが実行しようとしているすべてのテストに対して MSTest アダプターが呼び出すITestFilter実装としてTFilterを登録するTestFilterProviderAttributeの厳密に型指定されたバリアント。

[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 を実装し、パブリック パラメーターなしのコンストラクターを公開する必要があります。

それ以外の動作は、"テスト アセンブリごとに最大 1 つ" ルールなど、 TestFilterProviderAttributeとまったく同じように動作します。2 つの属性は 1 つと同じ登録としてカウントされるため、両方を 1 つのアセンブリに適用するとエラーになります。 これらは個別の型であるため、コンパイラは重複する属性として報告しません。 MSTEST0081 します。

この属性は、.NETを対象とする場合にのみ使用できます。 .NET Framework では、非ジェネリック TestFilterProviderAttributeを使用します。 両方を複数ターゲットとするテスト プロジェクトでは、 #if NETで適切なフォームを選択できます。

#if NET
[assembly: TestFilterProvider<MyFilter>]
#else
[assembly: TestFilterProvider(typeof(MyFilter))]
#endif

コンストラクター

名前 説明
TestFilterProviderAttribute<TFilter>()

MSTest アダプターが実行しようとしているすべてのテストに対して MSTest アダプターが呼び出すITestFilter実装としてTFilterを登録するTestFilterProviderAttributeの厳密に型指定されたバリアント。

適用対象