Skip to content

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0042.md
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A test method has two or more [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute>) attributes which are equivalent.
A test method has two or more [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute) attributes that 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Do not suppress a warning from this rule.
Do not suppress a warning from this rule, unless you intended to use the same input more than once.

41 changes: 41 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0043.md
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.
10 changes: 8 additions & 2 deletions docs/core/testing/mstest-analyzers/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.:
This is the mode most developers are expected 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:


- [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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
This mode is more aggressive than `Recommended`. All rules are enabled as warnings. In addition, the following rules are escalated to errors:


- [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:
Expand Down
2 changes: 2 additions & 0 deletions docs/core/testing/mstest-analyzers/usage-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ Identifier | Name | Description
[MSTEST0039](mstest0039.md) | UseNewerAssertThrowsAnalyzer | Use newer 'Assert.Throws' methods
[MSTEST0040](mstest0040.md) | AvoidUsingAssertsInAsyncVoidContextAnalyzer | Do not assert inside 'async void' contexts
[MSTEST0041](mstest0041.md) | UseConditionBaseWithTestClassAnalyzer | Use 'ConditionBaseAttribute' on test classes
[MSTEST0042](mstest0042.md) | DuplicateDataRowAnalyzer | Avoid duplicated 'DataRow' entries
[MSTEST0043](mstest0043.md) | UseRetryWithTestMethodAnalyzer | Use retry attribute on test method
4 changes: 4 additions & 0 deletions docs/navigate/devops-testing/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ items:
href: ../../core/testing/mstest-analyzers/mstest0040.md
- name: MSTEST0041
href: ../../core/testing/mstest-analyzers/mstest0041.md
- name: MSTEST0042
href: ../../core/testing/mstest-analyzers/mstest0042.md
- name: MSTEST0043
href: ../../core/testing/mstest-analyzers/mstest0043.md
- name: Test platforms
items:
- name: Microsoft.Testing.Platform
Expand Down
Loading