Skip to content

Commit d14053e

Browse files
engyebrahimIEvangelistEvangelink
authored
MSTEST0032 Analyzer (dotnet#41732)
Co-authored-by: David Pine <[email protected]> Co-authored-by: Amaury Levé <[email protected]>
1 parent f038887 commit d14053e

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: "MSTEST0032: Review or remove the assertion as its condition is known to be always true."
3+
description: "Learn about code analysis rule MSTEST0032: Review or remove the assertion as its condition is known to be always true."
4+
ms.date: 07/11/2024
5+
f1_keywords:
6+
- MSTEST0032
7+
- ReviewAlwaysTrueAssertConditionAnalyzer
8+
helpviewer_keywords:
9+
- ReviewAlwaysTrueAssertConditionAnalyzer
10+
- MSTEST0032
11+
author: engyebrahim
12+
ms.author: enjieid
13+
---
14+
# MSTEST0032: Review or remove the assertion as its condition is known to be always true.
15+
16+
| Property | Value |
17+
|-------------------------------------|-----------------------------------------------------------------------------|
18+
| **Rule ID** | MSTEST0032 |
19+
| **Title** | Review or remove the assertion as its condition is known to be always true. |
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+
This rule raises a diagnostic when a call to an assertion produces an always-true condition.
29+
30+
## Rule description
31+
32+
When you encounter an assertion that always passes (for example, `Assert.IsTrue(true)`), it's not obvious to someone reading the code why the assertion is there or what condition it's trying to check. This can lead to confusion and wasted time for developers who come across the code later on.
33+
34+
## How to fix violations
35+
36+
Ensure that calls to `Assert.IsTrue`, `Assert.IsFalse`, `Assert.AreEqual`, `Assert.AreNotEqual`, `Assert.IsNull` or `Assert.IsNotNull` aren't producing always-true conditions.
37+
38+
## When to suppress warnings
39+
40+
It's _not_ recommended to suppress warnings from this rule.

docs/navigate/devops-testing/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ items:
147147
href: ../../core/testing/mstest-analyzers/mstest0030.md
148148
- name: MSTEST0031
149149
href: ../../core/testing/mstest-analyzers/mstest0031.md
150+
- name: MSTEST0032
151+
href: ../../core/testing/mstest-analyzers/mstest0032.md
150152
- name: Microsoft Testing Platform
151153
items:
152154
- name: Overview

0 commit comments

Comments
 (0)