Skip to content

Commit

Permalink
Add documentation for analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Dec 15, 2023
1 parent 221013d commit 5b0d2a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/analyzers/MSTEST0001.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# MSTEST0001

| Property | Value |
|-------------------------------------|-----------------------------------------------------|
| **Rule ID** | MSTEST0001 |
| **Title** | Explicitly enable or disable tests parallelization. |
| **Category** | [Performance](performance-warnings.md) |
| **Enabled by default in .NET 8** | Yes |

## Cause

The assembly is not marked with `[Parallelize]` or `[DoNotParallelize]` attribute.

## Rule description

By default, MSTest runs tests sequentially which can lead to severe performance limitations. It is recommended to enable assembly attribute `[Parallelize]` or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute `[DoNotParallelize]`.

## How to fix violations

Add `[assembly: Parallelize]` or `[assembly: DoNotParallelize]` attribute.
9 changes: 9 additions & 0 deletions docs/analyzers/analyzers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# MSTest analyzers

MSTest.Analyzers provide a set of rules for C# and VB.NET that helps a better usage of MSTest APIs. The diagnostics are organized into categories such as performance, usage...

## Categories

**[Performance rules](PerformanceRules.md)**

Rules that support high-performance testing.
7 changes: 7 additions & 0 deletions docs/analyzers/performance-warnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Performance rules

Rules that support high-performance testing.

Identifier | Name | Description
-----------|------|------------
[MSTEST0001](MSTEST0001.md) | UseParallelizeAttributeAnalyzer | By default, MSTest runs tests sequentially which can lead to severe performance limitations. It is recommended to enable assembly attribute `[Parallelize]` or if the assembly is known to not be parallelizable, to use explicitly the assembly level attribute `[DoNotParallelize]`.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ public sealed class UseParallelizeAttributeAnalyzer : DiagnosticAnalyzer
private static readonly LocalizableResourceString Title = new(nameof(Resources.UseParallelizeAttributeAnalyzerTitle), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableResourceString MessageFormat = new(nameof(Resources.UseParallelizeAttributeAnalyzerMessageFormat), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableResourceString Description = new(nameof(Resources.UseParallelizeAttributeAnalyzerDescription), Resources.ResourceManager, typeof(Resources));
internal static readonly DiagnosticDescriptor Rule = new(DiagnosticIds.UseParallelizedAttributeRuleId, Title, MessageFormat, Categories.Performance, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description, customTags: WellKnownCustomTags.CompilationEnd);
internal static readonly DiagnosticDescriptor Rule = new(
DiagnosticIds.UseParallelizedAttributeRuleId,
Title,
MessageFormat,
Categories.Performance,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
Description,
$"https://github.com/microsoft/testfx/blob/main/docs/analyzers/{DiagnosticIds.UseParallelizedAttributeRuleId}.md",
WellKnownCustomTags.CompilationEnd);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; }
= ImmutableArray.Create(Rule);
Expand Down

0 comments on commit 5b0d2a6

Please sign in to comment.