-
Notifications
You must be signed in to change notification settings - Fork 6k
Document MSTEST0042 and MSTEST0043 #45783
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
Open
Youssef1313
wants to merge
2
commits into
dotnet:main
Choose a base branch
from
Youssef1313:analyzers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,41 @@ | ||||||
--- | ||||||
title: "MSTEST0042: Avoid duplicated 'DataRow' entries" | ||||||
description: "Learn about code analysis rule MSTEST0042: Avoid duplicated 'DataRow' entries" | ||||||
ms.date: 04/11/2025 | ||||||
f1_keywords: | ||||||
- MSTEST0042 | ||||||
- DuplicateDataRowAnalyzer | ||||||
helpviewer_keywords: | ||||||
- DuplicateDataRowAnalyzer | ||||||
- MSTEST0042 | ||||||
author: Youssef1313 | ||||||
ms.author: ygerges | ||||||
--- | ||||||
# MSTEST0042: Avoid duplicated 'DataRow' entries | ||||||
|
||||||
| Property | Value | | ||||||
|-------------------------------------|------------------------------------------------------------------------| | ||||||
| **Rule ID** | MSTEST0042 | | ||||||
| **Title** | Avoid duplicated 'DataRow' entries | | ||||||
| **Category** | Usage | | ||||||
| **Fix is breaking or non-breaking** | Non-breaking | | ||||||
| **Enabled by default** | Yes | | ||||||
| **Default severity** | Warning | | ||||||
| **Introduced in version** | 3.9.0 | | ||||||
| **Is there a code fix** | No | | ||||||
|
||||||
## Cause | ||||||
|
||||||
A test method has two or more [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute>) attributes which are equivalent. | ||||||
|
||||||
## Rule description | ||||||
|
||||||
<xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute> is used to denote inputs to test methods. It's not expected that a test will intentionally run twice with the exact same data. Duplicated `DataRow`s are often a copy/paste error. | ||||||
|
||||||
## How to fix violations | ||||||
|
||||||
Either remove the duplicate `DataRow` attribute, or fix it to make unique. | ||||||
|
||||||
## When to suppress warnings | ||||||
|
||||||
Do not suppress a warning from this rule. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
This file contains 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,41 @@ | ||
--- | ||
title: "MSTEST0043: Use retry attribute on test method" | ||
description: "Learn about code analysis rule MSTEST0043: Use retry attribute on test method" | ||
ms.date: 04/11/2025 | ||
f1_keywords: | ||
- MSTEST0043 | ||
- UseRetryWithTestMethodAnalyzer | ||
helpviewer_keywords: | ||
- UseRetryWithTestMethodAnalyzer | ||
- MSTEST0043 | ||
author: Youssef1313 | ||
ms.author: ygerges | ||
--- | ||
# MSTEST0043: Use retry attribute on test method | ||
|
||
| Property | Value | | ||
|-------------------------------------|------------------------------------------------------------------------------------------| | ||
| **Rule ID** | MSTEST0043 | | ||
| **Title** | Use retry attribute on test method | | ||
| **Category** | Usage | | ||
| **Fix is breaking or non-breaking** | Non-breaking | | ||
| **Enabled by default** | Yes | | ||
| **Default severity** | Warning (escalated to Error when setting `MSTestAnalysisMode` to `Recommended` or `All`) | | ||
| **Introduced in version** | 3.9.0 | | ||
| **Is there a code fix** | No | | ||
|
||
## Cause | ||
|
||
A method has an attribute that derives from <xref:Microsoft.VisualStudio.TestTools.UnitTesting.RetryBaseAttribute> and does not have an attribute that derives from <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute>. | ||
|
||
## Rule description | ||
|
||
<xref:Microsoft.VisualStudio.TestTools.UnitTesting.RetryBaseAttribute> only applies to test methods. | ||
|
||
## How to fix violations | ||
|
||
Add <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute> to the method, or remove the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.RetryBaseAttribute>. | ||
|
||
## When to suppress warnings | ||
|
||
Do not suppress a warning from this rule. |
This file contains 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 | ||||
---|---|---|---|---|---|---|
|
@@ -49,11 +49,17 @@ This setting follows the default documented behavior for each rule. | |||||
|
||||||
### `Recommended` | ||||||
|
||||||
This is the mode we expect most developers to use. Rules that are enabled by default with Info (`suggestion`) severity are escalated to warnings. Moreover, certain rules might be escalated to errors in both `Recommended` and `All` modes. For example, [MSTEST0003: Test methods should have valid layout](mstest0003.md) is escalated to error in `Recommended` and `All` modes. | ||||||
This is the mode we expect most developers to use. Rules that are enabled by default with Info (`suggestion`) severity are escalated to warnings. The following rules are escalated to errors in both `Recommended` and `All` modes.: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- [MSTEST0003: Test methods should have valid layout](mstest0003.md). | ||||||
- [MSTEST0043: Use retry attribute on test method](mstest0043.md). | ||||||
|
||||||
### `All` | ||||||
|
||||||
This mode is more aggressive than `Recommended`. All rules are enabled as warnings. As mentioned for `Recommended` mode, certain rules might be escalated to errors in both `Recommended` and `All` modes. For example, [MSTEST0003: Test methods should have valid layout](./mstest0003.md) is escalated to error in `Recommended` and `All` modes. | ||||||
This mode is more aggressive than `Recommended`. All rules are enabled as warnings. As mentioned for `Recommended` mode. The following rules are escalated to errors in `Reommended` and `All` modes: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
- [MSTEST0003: Test methods should have valid layout](mstest0003.md). | ||||||
- [MSTEST0043: Use retry attribute on test method](mstest0043.md). | ||||||
|
||||||
> [!NOTE] | ||||||
> The following rules are completely opt-in and are not enabled in `Default`, `Recommended`, or `All` modes: | ||||||
|
This file contains 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
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.