Skip to content

Commit 2fbe181

Browse files
Fix or add more details about some MSTest rules (#41885)
Co-authored-by: David Pine <[email protected]>
1 parent 13c32df commit 2fbe181

File tree

9 files changed

+29
-3
lines changed

9 files changed

+29
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The type declaring these methods should also respect the following rules:
2+
3+
- The type should be a `class`.
4+
- The `class` should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute).
5+
- The `class` shouldn't be `static`.
6+
- If the `class` is `sealed`, it should be marked with `[TestClass]` (or a derived attribute).

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Methods marked with `[TestInitialize]` should follow the following layout to be
4040
- it should not take any parameter
4141
- return type should be `void`, `Task` or `ValueTask`
4242

43+
[!INCLUDE [test-class-rules](includes/test-class-rules.md)]
44+
4345
## How to fix violations
4446

4547
Ensure that the method matches the layout described above.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Methods marked with `[TestCleanup]` should follow the following layout to be val
4040
- it should not take any parameter
4141
- return type should be `void`, `Task` or `ValueTask`
4242

43+
[!INCLUDE [test-class-rules](includes/test-class-rules.md)]
44+
4345
## How to fix violations
4446

4547
Ensure that the method matches the layout described above.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Methods marked with `[ClassInitialize]` should follow the following layout to be
4040
- it should take one parameter of type `TestContext`
4141
- return type should be `void`, `Task` or `ValueTask`
4242

43+
[!INCLUDE [test-class-rules](includes/test-class-rules.md)]
44+
45+
- the class should not be generic
46+
4347
## How to fix violations
4448

4549
Ensure that the method matches the layout described above.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Methods marked with `[ClassCleanup]` should follow the following layout to be va
4040
- it should not take any parameter
4141
- return type should be `void`, `Task` or `ValueTask`
4242

43+
[!INCLUDE [test-class-rules](includes/test-class-rules.md)]
44+
45+
- the class should not be generic
46+
4347
## How to fix violations
4448

4549
Ensure that the method matches the layout described above.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Methods marked with `[AssemblyInitialize]` should follow the following layout to
4040
- it should take one parameter of type `TestContext`
4141
- return type should be `void`, `Task` or `ValueTask`
4242

43+
[!INCLUDE [test-class-rules](includes/test-class-rules.md)]
44+
45+
- the class should not be generic
46+
4347
## How to fix violations
4448

4549
Ensure that the method matches the layout described above.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Methods marked with `[AssemblyCleanup]` should follow the following layout to be
4040
- it should not take any parameter
4141
- return type should be `void`, `Task` or `ValueTask`
4242

43+
[!INCLUDE [test-class-rules](includes/test-class-rules.md)]
44+
45+
- the class should not be generic
46+
4347
## How to fix violations
4448

4549
Ensure that the method matches the layout described above.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ ms.author: enjieid
2525

2626
## Cause
2727

28-
A Public method should be a test method.
28+
A `public` method should be a test method.
2929

3030
## Rule description
3131

32-
A Public method should be a test method (marked with `[TestMethod]`).
32+
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.
3333

3434
## How to fix violations
3535

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ms.author: enjieid
2525

2626
## Cause
2727

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

3030
## Rule description
3131

0 commit comments

Comments
 (0)