From 7ca673e7ae2d3c69bcb93b3e7f7ec0f68e0f08ab Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 11 Apr 2025 09:58:13 +0200 Subject: [PATCH 1/3] Document MSTEST0042 analyzer --- .../testing/mstest-analyzers/mstest0042.md | 41 +++++++++++++++++++ .../testing/mstest-analyzers/usage-rules.md | 1 + docs/navigate/devops-testing/toc.yml | 2 + 3 files changed, 44 insertions(+) create mode 100644 docs/core/testing/mstest-analyzers/mstest0042.md diff --git a/docs/core/testing/mstest-analyzers/mstest0042.md b/docs/core/testing/mstest-analyzers/mstest0042.md new file mode 100644 index 0000000000000..5abe2467a2150 --- /dev/null +++ b/docs/core/testing/mstest-analyzers/mstest0042.md @@ -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 + + 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. diff --git a/docs/core/testing/mstest-analyzers/usage-rules.md b/docs/core/testing/mstest-analyzers/usage-rules.md index 120458aad2c48..d63f178fda354 100644 --- a/docs/core/testing/mstest-analyzers/usage-rules.md +++ b/docs/core/testing/mstest-analyzers/usage-rules.md @@ -38,3 +38,4 @@ 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 diff --git a/docs/navigate/devops-testing/toc.yml b/docs/navigate/devops-testing/toc.yml index 03a0fff1e4bb1..2d01e9e81dacf 100644 --- a/docs/navigate/devops-testing/toc.yml +++ b/docs/navigate/devops-testing/toc.yml @@ -207,6 +207,8 @@ 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: Test platforms items: - name: Microsoft.Testing.Platform From 00f3242d4fad1f91f3d6c9c524e358c5cbecaa5f Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 11 Apr 2025 10:09:15 +0200 Subject: [PATCH 2/3] Document MSTEST0043 analyzer --- .../testing/mstest-analyzers/mstest0043.md | 41 +++++++++++++++++++ .../core/testing/mstest-analyzers/overview.md | 10 ++++- .../testing/mstest-analyzers/usage-rules.md | 1 + docs/navigate/devops-testing/toc.yml | 2 + 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 docs/core/testing/mstest-analyzers/mstest0043.md diff --git a/docs/core/testing/mstest-analyzers/mstest0043.md b/docs/core/testing/mstest-analyzers/mstest0043.md new file mode 100644 index 0000000000000..914e17e0d4128 --- /dev/null +++ b/docs/core/testing/mstest-analyzers/mstest0043.md @@ -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 and does not have an attribute that derives from . + +## Rule description + + only applies to test methods. + +## How to fix violations + +Add to the method, or remove the . + +## When to suppress warnings + +Do not suppress a warning from this rule. diff --git a/docs/core/testing/mstest-analyzers/overview.md b/docs/core/testing/mstest-analyzers/overview.md index d8bd11d084fe9..41dff8ad8133b 100644 --- a/docs/core/testing/mstest-analyzers/overview.md +++ b/docs/core/testing/mstest-analyzers/overview.md @@ -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.: + +- [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: + +- [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: diff --git a/docs/core/testing/mstest-analyzers/usage-rules.md b/docs/core/testing/mstest-analyzers/usage-rules.md index d63f178fda354..8f6723072467a 100644 --- a/docs/core/testing/mstest-analyzers/usage-rules.md +++ b/docs/core/testing/mstest-analyzers/usage-rules.md @@ -39,3 +39,4 @@ Identifier | Name | Description [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 diff --git a/docs/navigate/devops-testing/toc.yml b/docs/navigate/devops-testing/toc.yml index 2d01e9e81dacf..96cf78d381915 100644 --- a/docs/navigate/devops-testing/toc.yml +++ b/docs/navigate/devops-testing/toc.yml @@ -209,6 +209,8 @@ items: 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 From 4832e6b87a890724d919b980c8b7e6ef3b1f6ccb Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 23 Apr 2025 10:08:16 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- docs/core/testing/mstest-analyzers/mstest0042.md | 4 ++-- docs/core/testing/mstest-analyzers/overview.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/core/testing/mstest-analyzers/mstest0042.md b/docs/core/testing/mstest-analyzers/mstest0042.md index 5abe2467a2150..f4a05e30dd534 100644 --- a/docs/core/testing/mstest-analyzers/mstest0042.md +++ b/docs/core/testing/mstest-analyzers/mstest0042.md @@ -26,7 +26,7 @@ ms.author: ygerges ## Cause -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 @@ -38,4 +38,4 @@ Either remove the duplicate `DataRow` attribute, or fix it to make unique. ## When to suppress warnings -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. diff --git a/docs/core/testing/mstest-analyzers/overview.md b/docs/core/testing/mstest-analyzers/overview.md index 41dff8ad8133b..04df8a6d0c1b9 100644 --- a/docs/core/testing/mstest-analyzers/overview.md +++ b/docs/core/testing/mstest-analyzers/overview.md @@ -49,14 +49,14 @@ 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. 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. 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).