Skip to content

Commit a0b9676

Browse files
Document MSTEST0042 and MSTEST0043 (#45783)
* Document MSTEST0042 analyzer * Document MSTEST0043 analyzer * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]> --------- Co-authored-by: Genevieve Warren <[email protected]>
1 parent 571c3d1 commit a0b9676

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "MSTEST0042: Avoid duplicated 'DataRow' entries"
3+
description: "Learn about code analysis rule MSTEST0042: Avoid duplicated 'DataRow' entries"
4+
ms.date: 04/11/2025
5+
f1_keywords:
6+
- MSTEST0042
7+
- DuplicateDataRowAnalyzer
8+
helpviewer_keywords:
9+
- DuplicateDataRowAnalyzer
10+
- MSTEST0042
11+
author: Youssef1313
12+
ms.author: ygerges
13+
---
14+
# MSTEST0042: Avoid duplicated 'DataRow' entries
15+
16+
| Property | Value |
17+
|-------------------------------------|------------------------------------------------------------------------|
18+
| **Rule ID** | MSTEST0042 |
19+
| **Title** | Avoid duplicated 'DataRow' entries |
20+
| **Category** | Usage |
21+
| **Fix is breaking or non-breaking** | Non-breaking |
22+
| **Enabled by default** | Yes |
23+
| **Default severity** | Warning |
24+
| **Introduced in version** | 3.9.0 |
25+
| **Is there a code fix** | No |
26+
27+
## Cause
28+
29+
A test method has two or more [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute) attributes that are equivalent.
30+
31+
## Rule description
32+
33+
<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.
34+
35+
## How to fix violations
36+
37+
Either remove the duplicate `DataRow` attribute, or fix it to make unique.
38+
39+
## When to suppress warnings
40+
41+
Do not suppress a warning from this rule, unless you intended to use the same input more than once.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "MSTEST0043: Use retry attribute on test method"
3+
description: "Learn about code analysis rule MSTEST0043: Use retry attribute on test method"
4+
ms.date: 04/11/2025
5+
f1_keywords:
6+
- MSTEST0043
7+
- UseRetryWithTestMethodAnalyzer
8+
helpviewer_keywords:
9+
- UseRetryWithTestMethodAnalyzer
10+
- MSTEST0043
11+
author: Youssef1313
12+
ms.author: ygerges
13+
---
14+
# MSTEST0043: Use retry attribute on test method
15+
16+
| Property | Value |
17+
|-------------------------------------|------------------------------------------------------------------------------------------|
18+
| **Rule ID** | MSTEST0043 |
19+
| **Title** | Use retry attribute on test method |
20+
| **Category** | Usage |
21+
| **Fix is breaking or non-breaking** | Non-breaking |
22+
| **Enabled by default** | Yes |
23+
| **Default severity** | Warning (escalated to Error when setting `MSTestAnalysisMode` to `Recommended` or `All`) |
24+
| **Introduced in version** | 3.9.0 |
25+
| **Is there a code fix** | No |
26+
27+
## Cause
28+
29+
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>.
30+
31+
## Rule description
32+
33+
<xref:Microsoft.VisualStudio.TestTools.UnitTesting.RetryBaseAttribute> only applies to test methods.
34+
35+
## How to fix violations
36+
37+
Add <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute> to the method, or remove the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.RetryBaseAttribute>.
38+
39+
## When to suppress warnings
40+
41+
Do not suppress a warning from this rule.

docs/core/testing/mstest-analyzers/overview.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ This setting follows the default documented behavior for each rule.
4949
5050
### `Recommended`
5151

52-
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.
52+
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:
53+
54+
- [MSTEST0003: Test methods should have valid layout](mstest0003.md).
55+
- [MSTEST0043: Use retry attribute on test method](mstest0043.md).
5356

5457
### `All`
5558

56-
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.
59+
This mode is more aggressive than `Recommended`. All rules are enabled as warnings. In addition, the following rules are escalated to errors:
60+
61+
- [MSTEST0003: Test methods should have valid layout](mstest0003.md).
62+
- [MSTEST0043: Use retry attribute on test method](mstest0043.md).
5763

5864
> [!NOTE]
5965
> The following rules are completely opt-in and are not enabled in `Default`, `Recommended`, or `All` modes:

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

+2
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ Identifier | Name | Description
3838
[MSTEST0039](mstest0039.md) | UseNewerAssertThrowsAnalyzer | Use newer 'Assert.Throws' methods
3939
[MSTEST0040](mstest0040.md) | AvoidUsingAssertsInAsyncVoidContextAnalyzer | Do not assert inside 'async void' contexts
4040
[MSTEST0041](mstest0041.md) | UseConditionBaseWithTestClassAnalyzer | Use 'ConditionBaseAttribute' on test classes
41+
[MSTEST0042](mstest0042.md) | DuplicateDataRowAnalyzer | Avoid duplicated 'DataRow' entries
42+
[MSTEST0043](mstest0043.md) | UseRetryWithTestMethodAnalyzer | Use retry attribute on test method

docs/navigate/devops-testing/toc.yml

+4
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ items:
207207
href: ../../core/testing/mstest-analyzers/mstest0040.md
208208
- name: MSTEST0041
209209
href: ../../core/testing/mstest-analyzers/mstest0041.md
210+
- name: MSTEST0042
211+
href: ../../core/testing/mstest-analyzers/mstest0042.md
212+
- name: MSTEST0043
213+
href: ../../core/testing/mstest-analyzers/mstest0043.md
210214
- name: Test platforms
211215
items:
212216
- name: Microsoft.Testing.Platform

0 commit comments

Comments
 (0)