TestFilterContext Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 |
| 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 |
| ManagedMethodName |
Gets or sets the method name in ECMA-335 metadata form, or |
| ManagedTypeName |
Gets or sets the declaring type name in ECMA-335 metadata form, or |
| MethodArity |
Gets or sets the number of generic type parameters declared on the test method,
or |
| 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 |
| ParameterTypeFullNames |
Gets or sets the ECMA-335-style fully qualified parameter type names of the test method,
or |
| Priority |
Gets or sets the PriorityAttribute value declared on the test, or
|
| 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. |