แก้ไข

แชร์ผ่าน


MSTEST0007: Use test attributes only on test methods

Property Value
Rule ID MSTEST0007
Title Use test attributes only on test methods
Category Usage
Fix is breaking or non-breaking Non-breaking
Enabled by default Yes
Default severity Info
Introduced in version 3.3.0
Is there a code fix Yes

Cause

A method that's not marked with TestMethodAttribute has one or more test attributes applied to it.

Rule description

The following test attributes should only be applied on methods marked with the TestMethodAttribute attribute:

How to fix violations

To fix a violation of this rule, either convert the method on which you applied the test attributes to a test method by setting the [TestMethod] attribute or remove the test attributes altogether.

When to suppress warnings

Do not suppress a warning from this rule. If you ignore this rule, your attributes will be ignored since they are designed for use only in a test context.

Suppress a warning

If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

#pragma warning disable MSTEST0007
// The code that's violating the rule is on this line.
#pragma warning restore MSTEST0007

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

[*.{cs,vb}]
dotnet_diagnostic.MSTEST0007.severity = none

For more information, see How to suppress code analysis warnings.