Edit

MSTEST0041: Use 'ConditionBaseAttribute' on test classes

Property Value
Rule ID MSTEST0041
Title Use 'ConditionBaseAttribute' on test classes
Category Usage
Fix is breaking or non-breaking Non-breaking
Enabled by default Yes
Default severity Warning
Introduced in version 3.8.0
Is there a code fix Yes, starting with MSTest 4.4

Cause

The use of an attribute that inherits from ConditionBaseAttribute on a class that is not marked with TestClassAttribute.

Rule description

An attribute that derives from ConditionBaseAttribute only has an effect when applied to a class that's marked with TestClassAttribute.

Conditions control whether MSTest runs a discovered test target; they don't declare a test class themselves. On an ordinary helper class, the condition can look like test policy without participating in test discovery or execution. This rule catches that mismatch between the apparent policy and the tests the runner actually recognizes.

How to fix violations

Depending on the intent, either add the missing TestClassAttribute or remove the attribute that derives from ConditionBaseAttribute.

Starting with MSTest 4.4, the code fix adds [TestClass] to the affected type.

When to suppress warnings

Do not suppress a warning from this rule.