Skip to content

Commit

Permalink
Fix or add more details about some MSTest rules (#41885)
Browse files Browse the repository at this point in the history
Co-authored-by: David Pine <[email protected]>
  • Loading branch information
Evangelink and IEvangelist authored Jul 26, 2024
1 parent 13c32df commit 2fbe181
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The type declaring these methods should also respect the following rules:

- The type should be a `class`.
- The `class` should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute).
- The `class` shouldn't be `static`.
- If the `class` is `sealed`, it should be marked with `[TestClass]` (or a derived attribute).
2 changes: 2 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0008.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Methods marked with `[TestInitialize]` should follow the following layout to be
- it should not take any parameter
- return type should be `void`, `Task` or `ValueTask`

[!INCLUDE [test-class-rules](includes/test-class-rules.md)]

## How to fix violations

Ensure that the method matches the layout described above.
Expand Down
2 changes: 2 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0009.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Methods marked with `[TestCleanup]` should follow the following layout to be val
- it should not take any parameter
- return type should be `void`, `Task` or `ValueTask`

[!INCLUDE [test-class-rules](includes/test-class-rules.md)]

## How to fix violations

Ensure that the method matches the layout described above.
Expand Down
4 changes: 4 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0010.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Methods marked with `[ClassInitialize]` should follow the following layout to be
- it should take one parameter of type `TestContext`
- return type should be `void`, `Task` or `ValueTask`

[!INCLUDE [test-class-rules](includes/test-class-rules.md)]

- the class should not be generic

## How to fix violations

Ensure that the method matches the layout described above.
Expand Down
4 changes: 4 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0011.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Methods marked with `[ClassCleanup]` should follow the following layout to be va
- it should not take any parameter
- return type should be `void`, `Task` or `ValueTask`

[!INCLUDE [test-class-rules](includes/test-class-rules.md)]

- the class should not be generic

## How to fix violations

Ensure that the method matches the layout described above.
Expand Down
4 changes: 4 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0012.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Methods marked with `[AssemblyInitialize]` should follow the following layout to
- it should take one parameter of type `TestContext`
- return type should be `void`, `Task` or `ValueTask`

[!INCLUDE [test-class-rules](includes/test-class-rules.md)]

- the class should not be generic

## How to fix violations

Ensure that the method matches the layout described above.
Expand Down
4 changes: 4 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0013.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Methods marked with `[AssemblyCleanup]` should follow the following layout to be
- it should not take any parameter
- return type should be `void`, `Task` or `ValueTask`

[!INCLUDE [test-class-rules](includes/test-class-rules.md)]

- the class should not be generic

## How to fix violations

Ensure that the method matches the layout described above.
Expand Down
4 changes: 2 additions & 2 deletions docs/core/testing/mstest-analyzers/mstest0029.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ ms.author: enjieid

## Cause

A Public method should be a test method.
A `public` method should be a test method.

## Rule description

A Public method should be a test method (marked with `[TestMethod]`).
A `public` method of a class marked with `[TestClass]` should be a test method (marked with `[TestMethod]`). The rule ignores methods that are marked with `[TestInitialize]`, or `[TestCleanup]` attributes.

## How to fix violations

Expand Down
2 changes: 1 addition & 1 deletion docs/core/testing/mstest-analyzers/mstest0030.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ms.author: enjieid

## Cause

Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored.
Type containing `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored.

## Rule description

Expand Down

0 comments on commit 2fbe181

Please sign in to comment.