From 03339d7e77bf64ac81b845f33237f818e979a77f Mon Sep 17 00:00:00 2001 From: Enji Eid Date: Tue, 2 Jul 2024 13:38:18 +0200 Subject: [PATCH 1/4] Create mstest0030.md --- docs/core/testing/mstest-analyzers/mstest0030.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/core/testing/mstest-analyzers/mstest0030.md diff --git a/docs/core/testing/mstest-analyzers/mstest0030.md b/docs/core/testing/mstest-analyzers/mstest0030.md new file mode 100644 index 0000000000000..8b137891791fe --- /dev/null +++ b/docs/core/testing/mstest-analyzers/mstest0030.md @@ -0,0 +1 @@ + From 18221522eef2b478468aa804fef0db4bb1317b13 Mon Sep 17 00:00:00 2001 From: Enji Eid Date: Tue, 2 Jul 2024 13:57:12 +0200 Subject: [PATCH 2/4] Update mstest0030.md --- .../testing/mstest-analyzers/mstest0030.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/core/testing/mstest-analyzers/mstest0030.md b/docs/core/testing/mstest-analyzers/mstest0030.md index 8b137891791fe..dbf58d74d083c 100644 --- a/docs/core/testing/mstest-analyzers/mstest0030.md +++ b/docs/core/testing/mstest-analyzers/mstest0030.md @@ -1 +1,40 @@ +--- +title: "MSTEST0030: Type containing `[TestMethod]` should be marked with `[TestClass]`" +description: "Learn about code analysis rule MSTEST0030: Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored." +ms.date: 07/02/2024 +f1_keywords: +- MSTEST0030 +- TypeContainingTestMethodShouldBeATestClass +helpviewer_keywords: +- TypeContainingTestMethodShouldBeATestClass +- MSTEST0030 +author: engyebrahim +ms.author: enjieid +--- +# MSTEST0030: Type containing `[TestMethod]` should be marked with `[TestClass]` +| Property | Value | +|-------------------------------------|--------------------------------------------------------------------| +| **Rule ID** | MSTEST0030 | +| **Title** | Type containing `[TestMethod]` should be marked with `[TestClass]` | +| **Category** | Usage | +| **Fix is breaking or non-breaking** | Non-breaking | +| **Enabled by default** | Yes | +| **Default severity** | Info | +| **Introduced in version** | 3.5.0 | + +## Cause + +Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored. + +## Rule description + +Type contaning `[TestMethod]` which is not abstacted should be marked with `[TestClass]`, otherwise the test method will be silently ignored. + +## How to fix violations + +A non-abstract class contains test methods should be marked with '[TestClass]'. + +## When to suppress warnings + +We do not recommend suppressing warnings from this rule, otherwise the test method will be silently ignored. From 85f26a0ac9d4c41e3ac71c587c6e9fdf982195d4 Mon Sep 17 00:00:00 2001 From: Enji Eid Date: Tue, 2 Jul 2024 13:59:09 +0200 Subject: [PATCH 3/4] Update toc.yml --- docs/navigate/devops-testing/toc.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/navigate/devops-testing/toc.yml b/docs/navigate/devops-testing/toc.yml index 4904348d12339..cd70e694f362b 100644 --- a/docs/navigate/devops-testing/toc.yml +++ b/docs/navigate/devops-testing/toc.yml @@ -143,6 +143,8 @@ items: href: ../../core/testing/mstest-analyzers/mstest0024.md - name: MSTEST0026 href: ../../core/testing/mstest-analyzers/mstest0026.md + - name: MSTEST0030 + href: ../../core/testing/mstest-analyzers/mstest0030.md - name: Microsoft Testing Platform items: - name: Overview From 211d57647380842c7a25060c47c0a612f19f505a Mon Sep 17 00:00:00 2001 From: Enji Eid Date: Tue, 2 Jul 2024 16:30:55 +0200 Subject: [PATCH 4/4] Update mstest0030.md --- docs/core/testing/mstest-analyzers/mstest0030.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/testing/mstest-analyzers/mstest0030.md b/docs/core/testing/mstest-analyzers/mstest0030.md index dbf58d74d083c..4894942740f02 100644 --- a/docs/core/testing/mstest-analyzers/mstest0030.md +++ b/docs/core/testing/mstest-analyzers/mstest0030.md @@ -29,7 +29,7 @@ Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the ## Rule description -Type contaning `[TestMethod]` which is not abstacted should be marked with `[TestClass]`, otherwise the test method will be silently ignored. +MSTest considers test methods only on the context of a test class container (a class marked with [TestClass] or derived attribute) which could lead to some tests being silently ignored. If your class is supposed to represent common test behavior to be executed by children classes, it's recommended to mark the type as abstract to clarify the intent for other developers reading the code. ## How to fix violations @@ -37,4 +37,4 @@ A non-abstract class contains test methods should be marked with '[TestClass]'. ## When to suppress warnings -We do not recommend suppressing warnings from this rule, otherwise the test method will be silently ignored. +It's safe to suppress the diagnostic if you are sure that your class is being inherited and that the tests declared on this class should only be run in the context of subclasses. Nonetheless, we recommend marking the class as abstract.