Skip to content

Commit f3f7659

Browse files
CopilotYoussef1313
andauthored
Document MSTEST0050 analyzer rule (#47608)
* Initial plan * Add documentation for MSTEST0050 analyzer rule Co-authored-by: Youssef1313 <[email protected]> * Fix MSTEST0050 default severity and code fix properties Co-authored-by: Youssef1313 <[email protected]> * Update MSTEST0050 documentation based on reviewer feedback - Change attribute names from AssemblyInitialize/AssemblyCleanup to GlobalTestInitialize/GlobalTestCleanup - Replace general violations list with specific method requirements - Simplify the "How to fix violations" section - Update usage-rules.md for consistency Co-authored-by: Youssef1313 <[email protected]> * Address reviewer feedback on MSTEST0050 documentation Co-authored-by: Youssef1313 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Youssef1313 <[email protected]>
1 parent d507481 commit f3f7659

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "MSTEST0050: Global test fixture should be valid"
3+
description: "Learn about code analysis rule MSTEST0050: Global test fixture should be valid"
4+
ms.date: 07/29/2025
5+
f1_keywords:
6+
- MSTEST0050
7+
- GlobalTestFixtureShouldBeValidAnalyzer
8+
helpviewer_keywords:
9+
- GlobalTestFixtureShouldBeValidAnalyzer
10+
- MSTEST0050
11+
author: Evangelink
12+
ms.author: amauryleve
13+
---
14+
# MSTEST0050: Global test fixture should be valid
15+
16+
| Property | Value |
17+
|-------------------------------------|------------------------------------------------------------------------------------------|
18+
| **Rule ID** | MSTEST0050 |
19+
| **Title** | Global test fixture should be valid |
20+
| **Category** | Usage |
21+
| **Fix is breaking or non-breaking** | Non-breaking |
22+
| **Enabled by default** | Yes |
23+
| **Default severity** | Error |
24+
| **Introduced in version** | 3.10.0 |
25+
| **Is there a code fix** | No |
26+
27+
## Cause
28+
29+
A global test fixture method (marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute`) doesn't follow the required layout or has invalid configuration.
30+
31+
## Rule description
32+
33+
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.
34+
35+
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`.
36+
37+
## How to fix violations
38+
39+
Ensure that global test fixture methods follow the required layout.
40+
41+
## When to suppress warnings
42+
43+
Don't suppress warnings from this rule. Invalid global test fixture methods will not execute at run-time.

docs/core/testing/mstest-analyzers/usage-rules.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ Identifier | Name | Description
4343
[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.
4444
[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.
4545
[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>.
46+
[MSTEST0050](mstest0050.md) | GlobalTestFixtureShouldBeValidAnalyzer | A global test fixture method (marked with `GlobalTestInitializeAttribute` or `GlobalTestCleanupAttribute`) doesn't follow the required layout or has invalid configuration.

docs/navigate/devops-testing/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ items:
225225
href: ../../core/testing/mstest-analyzers/mstest0048.md
226226
- name: MSTEST0049
227227
href: ../../core/testing/mstest-analyzers/mstest0049.md
228+
- name: MSTEST0050
229+
href: ../../core/testing/mstest-analyzers/mstest0050.md
228230
- name: Test platforms
229231
items:
230232
- name: Microsoft.Testing.Platform

0 commit comments

Comments
 (0)