diff --git a/docs/core/testing/mstest-analyzers/includes/test-class-rules.md b/docs/core/testing/mstest-analyzers/includes/test-class-rules.md new file mode 100644 index 0000000000000..f10f31a1d8332 --- /dev/null +++ b/docs/core/testing/mstest-analyzers/includes/test-class-rules.md @@ -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). diff --git a/docs/core/testing/mstest-analyzers/mstest0008.md b/docs/core/testing/mstest-analyzers/mstest0008.md index db4b8da4d15b3..de7c20be795c1 100644 --- a/docs/core/testing/mstest-analyzers/mstest0008.md +++ b/docs/core/testing/mstest-analyzers/mstest0008.md @@ -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. diff --git a/docs/core/testing/mstest-analyzers/mstest0009.md b/docs/core/testing/mstest-analyzers/mstest0009.md index b4e3cc25092a6..833587c742c55 100644 --- a/docs/core/testing/mstest-analyzers/mstest0009.md +++ b/docs/core/testing/mstest-analyzers/mstest0009.md @@ -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. diff --git a/docs/core/testing/mstest-analyzers/mstest0010.md b/docs/core/testing/mstest-analyzers/mstest0010.md index e9750d17922c8..6c61ce98294bf 100644 --- a/docs/core/testing/mstest-analyzers/mstest0010.md +++ b/docs/core/testing/mstest-analyzers/mstest0010.md @@ -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. diff --git a/docs/core/testing/mstest-analyzers/mstest0011.md b/docs/core/testing/mstest-analyzers/mstest0011.md index 587e3be81084e..de4ed0d1c0702 100644 --- a/docs/core/testing/mstest-analyzers/mstest0011.md +++ b/docs/core/testing/mstest-analyzers/mstest0011.md @@ -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. diff --git a/docs/core/testing/mstest-analyzers/mstest0012.md b/docs/core/testing/mstest-analyzers/mstest0012.md index c2d3239a2a311..23e901196273d 100644 --- a/docs/core/testing/mstest-analyzers/mstest0012.md +++ b/docs/core/testing/mstest-analyzers/mstest0012.md @@ -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. diff --git a/docs/core/testing/mstest-analyzers/mstest0013.md b/docs/core/testing/mstest-analyzers/mstest0013.md index 243e2f72347c7..4f0a6a4cdc67e 100644 --- a/docs/core/testing/mstest-analyzers/mstest0013.md +++ b/docs/core/testing/mstest-analyzers/mstest0013.md @@ -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. diff --git a/docs/core/testing/mstest-analyzers/mstest0029.md b/docs/core/testing/mstest-analyzers/mstest0029.md index b0597891973ab..8450d6758379d 100644 --- a/docs/core/testing/mstest-analyzers/mstest0029.md +++ b/docs/core/testing/mstest-analyzers/mstest0029.md @@ -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 diff --git a/docs/core/testing/mstest-analyzers/mstest0030.md b/docs/core/testing/mstest-analyzers/mstest0030.md index 4894942740f02..b0dfc7c6394e9 100644 --- a/docs/core/testing/mstest-analyzers/mstest0030.md +++ b/docs/core/testing/mstest-analyzers/mstest0030.md @@ -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