Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0050.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: "MSTEST0050: Global test fixture should be valid"
description: "Learn about code analysis rule MSTEST0050: Global test fixture should be valid"
ms.date: 07/29/2025
f1_keywords:
- MSTEST0050
- GlobalTestFixtureShouldBeValidAnalyzer
helpviewer_keywords:
- GlobalTestFixtureShouldBeValidAnalyzer
- MSTEST0050
author: Evangelink
ms.author: amauryleve
---
# MSTEST0050: Global test fixture should be valid

| Property | Value |
|-------------------------------------|------------------------------------------------------------------------------------------|
| **Rule ID** | MSTEST0050 |
| **Title** | Global test fixture should be valid |
| **Category** | Usage |
| **Fix is breaking or non-breaking** | Non-breaking |
| **Enabled by default** | Yes |
| **Default severity** | Error |
| **Introduced in version** | 3.10.0 |
| **Is there a code fix** | No |

## Cause

A global test fixture method (marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute`) doesn't follow the required layout or has invalid configuration.

## Rule description

Global test fixture methods must follow specific requirements to ensure proper test execution. This rule validates that methods marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute` adhere to the correct method signature and configuration rules.

The method must be `public`, `static`, non-generic, have a single parameter of type `TestContext`, and return `void` or `Task`. In addition, the containing type must be `public`, `static`, non-generic, and be marked with `TestClassAttribute`.

## How to fix violations

Ensure that global test fixture methods follow the required layout.

## When to suppress warnings

Don't suppress warnings from this rule. Invalid global test fixture methods will not execute at run-time.
1 change: 1 addition & 0 deletions docs/core/testing/mstest-analyzers/usage-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Identifier | Name | Description
[MSTEST0046](mstest0046.md) | StringAssertToAssertAnalyzer | A test method uses <xref:Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert> methods instead of equivalent <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Assert> methods.
[MSTEST0048](mstest0048.md) | TestContextPropertyUsageAnalyzer | A fixture method (methods with <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute>, <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute>, <xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute>, or <xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute>) accesses restricted <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> properties.
[MSTEST0049](mstest0049.md) | FlowTestContextCancellationTokenAnalyzer | A method call within a test context doesn't use the <xref:System.Threading.CancellationToken> available from <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> when the called method has a parameter or overload that accepts a <xref:System.Threading.CancellationToken>.
[MSTEST0050](mstest0050.md) | GlobalTestFixtureShouldBeValidAnalyzer | A global test fixture method (marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute`) doesn't follow the required layout or has invalid configuration.
2 changes: 2 additions & 0 deletions docs/navigate/devops-testing/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ items:
href: ../../core/testing/mstest-analyzers/mstest0048.md
- name: MSTEST0049
href: ../../core/testing/mstest-analyzers/mstest0049.md
- name: MSTEST0050
href: ../../core/testing/mstest-analyzers/mstest0050.md
- name: Test platforms
items:
- name: Microsoft.Testing.Platform
Expand Down