TestFilterContext Class

Definition

Snapshot of the metadata MSTest exposes to an ITestFilter for a single test under consideration.

public sealed class TestFilterContext
[System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")]
[System.Runtime.CompilerServices.Nullable(0)]
public sealed class TestFilterContext
type TestFilterContext = class
[<System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")>]
[<System.Runtime.CompilerServices.Nullable(0)>]
type TestFilterContext = class
Public NotInheritable Class TestFilterContext
Inheritance
TestFilterContext
Attributes

Remarks

Only metadata that is available without loading the test type is exposed; ITestFilter must be able to decide using strings, categories, traits, and priority alone. This is what allows the filter to drop tests before their declaring type is loaded and before [AssemblyInitialize] / [ClassInitialize] run.

Properties are mutable (settable) so the platform can populate them via an object initializer and so the type can grow new metadata fields over time without breaking existing ITestFilter implementations or their unit tests. MSTest itself does not mutate a TestFilterContext after it is handed to an ITestFilter; filters should likewise treat the instance they receive as effectively read-only for the duration of the call.

Each property describes a separate facet of the test. The flat string properties (FullyQualifiedName, DisplayName) are convenience views and are always populated. The structured properties (Namespace, ClassName, ManagedTypeName, ManagedMethodName, MethodArity, ParameterTypeFullNames) may be null when the metadata is not available — typically for tests discovered through code paths that don't surface ECMA-335 managed names.

The type is designed to be extended over time: new properties can be added without breaking existing ITestFilter implementations or their unit tests. Consumers construct instances using an object initializer (e.g. new TestFilterContext { FullyQualifiedName = "…" }); no positional constructor needs to be updated when new properties land.

Constructors

Name Description
TestFilterContext()

Properties

Name Description
Categories

Gets or sets the test categories declared via TestCategoryAttribute on the method or its declaring class. Defaults to an empty list.

ClassName

Gets or sets the simple class name (without namespace), or null when no managed metadata is available. Nested types are surfaced using their managed metadata form (e.g. Outer+Inner); see ManagedTypeName for the fully escaped ECMA-335 representation.

DisplayName

Gets or sets the display name of the test, as reported to the runner / IDE.

FullyQualifiedName

Gets or sets the fully qualified test name in Namespace.Class.Method form.

ManagedMethodName

Gets or sets the method name in ECMA-335 metadata form, or null when no managed metadata is available.

ManagedTypeName

Gets or sets the declaring type name in ECMA-335 metadata form, or null when no managed metadata is available.

MethodArity

Gets or sets the number of generic type parameters declared on the test method, or null when no managed metadata is available. Zero indicates a non-generic method.

MethodName

Gets or sets the unqualified test method name (i.e. without class or namespace).

Namespace

Gets or sets the namespace of the declaring test class, or null when no managed metadata is available or the class is in the global namespace.

ParameterTypeFullNames

Gets or sets the ECMA-335-style fully qualified parameter type names of the test method, or null when no managed metadata is available. An empty list indicates a parameterless method.

Priority

Gets or sets the PriorityAttribute value declared on the test, or null when no priority was declared.

Source

Gets or sets the path to the test assembly file containing this test.

Traits

Gets or sets the traits attached to this test. Multiple traits can share the same key; consumers must therefore not assume the collection behaves like a dictionary. Defaults to an empty list.

Applies to