Skip to content

Commit e119ec7

Browse files
committed
Fix or add more details about some MSTest rules
1 parent 49bab1a commit e119ec7

File tree

8 files changed

+49
-3
lines changed

8 files changed

+49
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ 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+
The type declaring these methods should also respect the following rules:
44+
45+
- the type should be a class
46+
- the class should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute)
47+
- the class should not be `static`
48+
- if the class is sealed, it should be marked with `[TestClass]` (or a derived attribute)
49+
4350
## How to fix violations
4451

4552
Ensure that the method matches the layout described above.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ 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+
The type declaring these methods should also respect the following rules:
44+
45+
- the type should be a class
46+
- the class should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute)
47+
- the class should not be `static`
48+
- if the class is sealed, it should be marked with `[TestClass]` (or a derived attribute)
49+
4350
## How to fix violations
4451

4552
Ensure that the method matches the layout described above.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ 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+
The type declaring these methods should also respect the following rules:
44+
45+
- the type should be a class
46+
- the class should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute)
47+
- the class should not be `static`
48+
- the class should not be generic
49+
- if the class is sealed, it should be marked with `[TestClass]` (or a derived attribute)
50+
4351
## How to fix violations
4452

4553
Ensure that the method matches the layout described above.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ 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+
The type declaring these methods should also respect the following rules:
44+
45+
- the type should be a class
46+
- the class should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute)
47+
- the class should not be `static`
48+
- the class should not be generic
49+
- if the class is sealed, it should be marked with `[TestClass]` (or a derived attribute)
50+
4351
## How to fix violations
4452

4553
Ensure that the method matches the layout described above.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ 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+
The type declaring these methods should also respect the following rules:
44+
45+
- the type should be a class
46+
- the class should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute)
47+
- the class should not be `static`
48+
- the class should not be generic
49+
- if the class is sealed, it should be marked with `[TestClass]` (or a derived attribute)
50+
4351
## How to fix violations
4452

4553
Ensure that the method matches the layout described above.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ 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+
The type declaring these methods should also respect the following rules:
44+
45+
- the type should be a class
46+
- the class should be `public` or `internal` (if the test project is using the `[DiscoverInternals]` attribute)
47+
- the class should not be `static`
48+
- the class should not be generic
49+
- if the class is sealed, it should be marked with `[TestClass]` (or a derived attribute)
50+
4351
## How to fix violations
4452

4553
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)