TestFilterProviderAttribute Klasa
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Rejestruje implementację dostarczoną przez ITestFilter użytkownika, którą karta MSTest wywołuje dla każdego testu, który ma zostać uruchomiony, po zastosowaniu filtru wiersza polecenia (--filterwyboru Eksploratora testów itp.).
[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
- Dziedziczenie
-
TestFilterProviderAttribute
- Atrybuty
Przykłady
[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;
}
Uwagi
Zastosuj ten atrybut na poziomie zestawu na samym zestawie testowym. Co najwyżej jeden TestFilterProviderAttribute może być stosowany dla zestawu testowego. Jest to celowe, aby kolejność filtrów nie jest częścią publicznego interfejsu API. Jeśli potrzebujesz wielu strategii filtrowania, utwórz je jawnie w ramach jednej ITestFilter implementacji.
Typ filtru musi być klasą niegeneryjną z publicznym konstruktorem bez parametrów, który implementuje ITestFilterelement . Pojedyncze wystąpienie jest tworzone na zestaw testowy na przebieg testu i ponownie używane dla każdego testu tego zestawu.
Filtr jest uruchamiany przed załadowaniem typu testu, przed [AssemblyInitialize], i przed [ClassInitialize]wywołaniem konstruktora testowego, więc upuszczanie lub pomijanie testu przez ITestFilter pozwala uniknąć płacenia któregokolwiek z tych kosztów.
Konstruktory
| Nazwa | Opis |
|---|---|
| TestFilterProviderAttribute(Type) |
Inicjuje nowe wystąpienie klasy TestFilterProviderAttribute. |
Właściwości
| Nazwa | Opis |
|---|---|
| FilterType |
Pobiera implementację zarejestrowaną ITestFilter przez ten atrybut. |