Skip to content

Commit 8400125

Browse files
Youssef1313Evangelinkgewarren
authored
Document MSTestAnalysisMode property (#44632)
* Document MSTestAnalysisMode property * Address review comments * Add info on finding the globalconfig * Doc in MSBuild reference for .NET SDK projects * Update docs/core/testing/mstest-analyzers/overview.md Co-authored-by: Amaury Levé <[email protected]> * Update analyzer doc pages for special treatments regarding MSTestAnalysisMode * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]> * Update docs/core/testing/mstest-analyzers/overview.md Co-authored-by: Genevieve Warren <[email protected]> --------- Co-authored-by: Amaury Levé <[email protected]> Co-authored-by: Genevieve Warren <[email protected]>
1 parent 843484f commit 8400125

File tree

9 files changed

+76
-10
lines changed

9 files changed

+76
-10
lines changed

docs/core/project-sdk/msbuild-props.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ The following MSBuild properties are documented in this section:
14571457
- [TestingPlatformShowTestsFailure](#testingplatformshowtestsfailure)
14581458
- [TestingExtensionsProfile](#testingextensionsprofile)
14591459
- [UseVSTest](#usevstest)
1460+
- [MSTestAnalysisMode](#mstestanalysismode)
14601461

14611462
### IsTestProject
14621463

@@ -1561,6 +1562,10 @@ For more information, see [MSTest runner profile](../testing/unit-testing-mstest
15611562

15621563
Set the `UseVSTest` property to `true` to switch from the MSTest runner to the [VSTest](/visualstudio/test/vstest-console-options) runner when using the [MSTest project SDK](../testing/unit-testing-mstest-sdk.md).
15631564

1565+
### MSTestAnalysisMode
1566+
1567+
This property decides which analyzers are enabled at which severity. For more information, see [MSTest code analysis](../testing/mstest-analyzers/overview.md).
1568+
15641569
## Hosting-related properties
15651570

15661571
The following MSBuild properties are documented in this section:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> [!NOTE]
2+
> This rule is opt-in. It's not enabled even when using `<MSTestAnalysisMode>All</MSTestAnalysisMode>`. For more information about `MSTestAnalysisMode`, see [MSTest code analysis](../overview.md).

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ dev_langs:
1616
---
1717
# MSTEST0003: Test methods should have valid layout
1818

19-
| Property | Value |
20-
|-------------------------------------|----------------------------------------------------|
21-
| **Rule ID** | MSTEST0003 |
22-
| **Title** | Test methods should have valid layout |
23-
| **Category** | Usage |
24-
| **Fix is breaking or non-breaking** | Breaking |
25-
| **Enabled by default** | Yes |
26-
| **Default severity** | Warning |
27-
| **Introduced in version** | 3.2.0 |
28-
| **Is there a code fix** | Yes |
19+
| Property | Value |
20+
|-------------------------------------|------------------------------------------------------------------------------------------|
21+
| **Rule ID** | MSTEST0003 |
22+
| **Title** | Test methods should have valid layout |
23+
| **Category** | Usage |
24+
| **Fix is breaking or non-breaking** | Breaking |
25+
| **Enabled by default** | Yes |
26+
| **Default severity** | Warning (escalated to Error when setting `MSTestAnalysisMode` to `Recommended` or `All`) |
27+
| **Introduced in version** | 3.2.0 |
28+
| **Is there a code fix** | Yes |
2929

3030
## Cause
3131

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Ensure that the test method isn't ignored.
4040

4141
Do not suppress a warning from this rule. If you ignore this rule, test method will be ignored.
4242

43+
[!INCLUDE [disabled-in-all](includes/disabled-in-all.md)]
44+
4345
## Suppress a warning
4446

4547
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Replace the constructor call with a `[TestInitialize]` method.
4040

4141
You usually don't want to suppress warnings from this rule if you decided to opt-in for it.
4242

43+
[!INCLUDE [disabled-in-all](includes/disabled-in-all.md)]
44+
4345
## Suppress a warning
4446

4547
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Replace `[TestInitialize]` returning `void` by constructors.
4040

4141
You usually don't want to suppress warnings from this rule if you decided to opt-in for it.
4242

43+
[!INCLUDE [disabled-in-all](includes/disabled-in-all.md)]
44+
4345
## Suppress a warning
4446

4547
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Replace `[TestCleanup]` method by `Dispose` or `DisposeAsync` pattern.
4040

4141
You usually don't want to suppress warnings from this rule if you decided to opt-in for it.
4242

43+
[!INCLUDE [disabled-in-all](includes/disabled-in-all.md)]
44+
4345
## Suppress a warning
4446

4547
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Replace `Dispose` or `DisposeAsync` methods with `[TestCleanup]`.
4040

4141
You usually don't want to suppress warnings from this rule if you decided to opt-in for it.
4242

43+
[!INCLUDE [disabled-in-all](includes/disabled-in-all.md)]
44+
4345
## Suppress a warning
4446

4547
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,55 @@ ms.date: 12/20/2023
1515
1616
The rules are organized into categories such as performance usage...
1717

18+
Starting with MSTest.TestFramework 3.7, the MSTest.Analyzers NuGet package is a dependency of the framework. For earlier versions, you need to use `MSTest` metapackage or add a package reference for `MSTest.Analyzers` explicitly.
19+
20+
## MSTestAnalysisMode
21+
22+
Starting with MSTest 3.8, an MSBuild property named `MSTestAnalysisMode` is available to determine which analyzers are enabled at which severity.
23+
24+
> [!TIP]
25+
> To see which rules are enabled at which severity for each mode, you can navigate to the package of the version of interest in NuGet cache, locate the `globalconfigs` directory, and open the `.globalconfig` file corresponding to the analysis mode.
26+
> For more information on finding the NuGet cache directory, see [Managing the global packages, cache, and temp folders](/nuget/consume-packages/managing-the-global-packages-and-cache-folders). From that directory, locate `mstest.analyzers` directory, then the version (3.8 and higher), then `globalconfigs`.
27+
> Alternatively, you can download the NuGet package of the version of interest from `nuget.org` and view it in NuGet Package Explorer (Windows app), or view directly in the [web app version of NuGet Package Explorer](https://nuget.info/packages/MSTest.Analyzers/).
28+
29+
The available values for this property:
30+
31+
- [`None`](#none)
32+
- [`Default`](#default)
33+
- [`Recommended`](#recommended)
34+
- [`All`](#all)
35+
36+
### `None`
37+
38+
This value sets all analyzers to `none` severity, disabling all of them. You can then enable individual analyzers using `.editorconfig` or `.globalconfig` files.
39+
40+
### `Default`
41+
42+
This setting follows the default documented behavior for each rule.
43+
44+
- Rules that are enabled by default will use their default severity.
45+
- Rules that are disabled by default will use `none` severity.
46+
47+
> [!NOTE]
48+
> Rules that are enabled by default as warnings are violations that are expected to cause issues at run time.
49+
50+
### `Recommended`
51+
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.
53+
54+
### `All`
55+
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.
57+
58+
> [!NOTE]
59+
> The following rules are completely opt-in and are not enabled in `Default`, `Recommended`, or `All` modes:
60+
>
61+
> - [MSTEST0015: Test method should not be ignored](mstest0015.md)
62+
> - [MSTEST0019: Prefer TestInitialize methods over constructors](mstest0019.md)
63+
> - [MSTEST0020: Prefer constructors over TestInitialize methods](mstest0020.md)
64+
> - [MSTEST0021: Prefer Dispose over TestCleanup methods](mstest0021.md)
65+
> - [MSTEST0022: Prefer TestCleanup over Dispose methods](mstest0022.md)
66+
1867
## Categories
1968

2069
### Design rules

0 commit comments

Comments
 (0)