Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/core/testing/mstest-analyzers/mstest0030.md
Original file line number Diff line number Diff line change
@@ -0,0 +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

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

A non-abstract class contains test methods should be marked with '[TestClass]'.

## When to suppress warnings

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.
2 changes: 2 additions & 0 deletions docs/navigate/devops-testing/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down