title | description | ms.date | f1_keywords | helpviewer_keywords | author | ms.author | ||||
---|---|---|---|---|---|---|---|---|---|---|
MSTEST0021: Prefer Dispose over TestCleanup methods |
Learn about code analysis rule MSTEST0021: Prefer Dispose over TestCleanup methods |
03/19/2024 |
|
|
Evangelink |
amauryleve |
Property | Value |
---|---|
Rule ID | MSTEST0021 |
Title | Prefer Dispose over TestCleanup methods |
Category | Design |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default | No |
Default severity | Info |
Introduced in version | 3.4.0 |
This rule raises a diagnostic when there is a void [TestCleanup]
method or on any [TestCleanup]
if the targeted framework supports IAsyncDisposable
interface.
Using Dispose
or DisposeAsync
is a more common pattern and some developers prefer to always use this pattern even for tests.
Replace [TestCleanup]
method by Dispose
or DisposeAsync
pattern.
You usually don't want to suppress warnings from this rule if you decided to opt-in for it.