Skip to content

Commit 46785ff

Browse files
authored
MSTEST0030: Type contaning [TestMethod] should be a [TestClass] (#41625)
1 parent 7038c86 commit 46785ff

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "MSTEST0030: Type containing `[TestMethod]` should be marked with `[TestClass]`"
3+
description: "Learn about code analysis rule MSTEST0030: Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored."
4+
ms.date: 07/02/2024
5+
f1_keywords:
6+
- MSTEST0030
7+
- TypeContainingTestMethodShouldBeATestClass
8+
helpviewer_keywords:
9+
- TypeContainingTestMethodShouldBeATestClass
10+
- MSTEST0030
11+
author: engyebrahim
12+
ms.author: enjieid
13+
---
14+
# MSTEST0030: Type containing `[TestMethod]` should be marked with `[TestClass]`
15+
16+
| Property | Value |
17+
|-------------------------------------|--------------------------------------------------------------------|
18+
| **Rule ID** | MSTEST0030 |
19+
| **Title** | Type containing `[TestMethod]` should be marked with `[TestClass]` |
20+
| **Category** | Usage |
21+
| **Fix is breaking or non-breaking** | Non-breaking |
22+
| **Enabled by default** | Yes |
23+
| **Default severity** | Info |
24+
| **Introduced in version** | 3.5.0 |
25+
26+
## Cause
27+
28+
Type contaning `[TestMethod]` should be marked with `[TestClass]`, otherwise the test method will be silently ignored.
29+
30+
## Rule description
31+
32+
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.
33+
34+
## How to fix violations
35+
36+
A non-abstract class contains test methods should be marked with '[TestClass]'.
37+
38+
## When to suppress warnings
39+
40+
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.

docs/navigate/devops-testing/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ items:
143143
href: ../../core/testing/mstest-analyzers/mstest0024.md
144144
- name: MSTEST0026
145145
href: ../../core/testing/mstest-analyzers/mstest0026.md
146+
- name: MSTEST0030
147+
href: ../../core/testing/mstest-analyzers/mstest0030.md
146148
- name: Microsoft Testing Platform
147149
items:
148150
- name: Overview

0 commit comments

Comments
 (0)