-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document MSTEST0050 analyzer rule #47608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+46
−0
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2af697
Initial plan
Copilot 7ed1358
Add documentation for MSTEST0050 analyzer rule
Copilot 869a9c4
Fix MSTEST0050 default severity and code fix properties
Copilot fc47267
Update MSTEST0050 documentation based on reviewer feedback
Copilot 56fefa5
Address reviewer feedback on MSTEST0050 documentation
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- | ||
| 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** | Warning | | ||
| | **Introduced in version** | 3.10.0 | | ||
| | **Is there a code fix** | Yes | | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Cause | ||
|
|
||
| A global test fixture method (marked with <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute> or <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute>) doesn't follow the required layout or has invalid configuration. | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Rule description | ||
|
|
||
| Global test fixture methods must follow specific requirements to ensure proper test execution. This rule validates that methods marked with <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute> or <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute> adhere to the correct method signature and configuration rules. | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Common violations include: | ||
|
|
||
| - Incorrect method signatures or parameters | ||
| - Invalid access modifiers | ||
| - Missing or incorrect return types | ||
| - Improper method declarations | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## How to fix violations | ||
|
|
||
| Ensure that global test fixture methods follow the required layout: | ||
|
|
||
| - Methods marked with <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute> should be `public static` and take a <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> parameter | ||
| - Methods marked with <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute> should be `public static` and optionally take a <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> parameter (starting with MSTest 3.6) | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## When to suppress warnings | ||
|
|
||
| Don't suppress warnings from this rule. Global test fixture methods with invalid layouts may not execute properly or may cause runtime errors. | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Example of a violation | ||
|
|
||
| ```csharp | ||
| [TestClass] | ||
| public class GlobalTestFixture | ||
| { | ||
| // Violation: AssemblyInitialize method should be static and take TestContext parameter | ||
| [AssemblyInitialize] | ||
| public void Setup() | ||
| { | ||
| // Setup code | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Example of how to fix | ||
|
|
||
| ```csharp | ||
| [TestClass] | ||
| public class GlobalTestFixture | ||
| { | ||
| // Fixed: Correct method signature for AssemblyInitialize | ||
| [AssemblyInitialize] | ||
| public static void Setup(TestContext testContext) | ||
| { | ||
| // Setup code | ||
| } | ||
| } | ||
| ``` | ||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.