Edit

Share via


MSTest usage rules

Rules that support proper usage of MSTest.

Identifier Name Description
MSTEST0002 TestClassShouldBeValidAnalyzer A test class is not following one or multiple points of the required test class layout.
MSTEST0003 TestMethodShouldBeValidAnalyzer A test method is not following single or multiple points of the required test method layout.
MSTEST0005 TestContextShouldBeValidAnalyzer A test context property is not following single or multiple points of the required test context layout.
MSTEST0007 UseAttributeOnTestMethodAnalyzer A method that's not marked with TestMethodAttribute has one or more test attributes applied to it.
MSTEST0008 TestInitializeShouldBeValidAnalyzer A method marked with [TestInitialize] should have valid layout.
MSTEST0009 TestCleanupShouldBeValidAnalyzer A method marked with [TestCleanup] should have valid layout.
MSTEST0010 ClassInitializeShouldBeValidAnalyzer A method marked with [ClassInitialize] should have valid layout.
MSTEST0011 ClassCleanupShouldBeValidAnalyzer A method marked with [ClassCleanup] should have valid layout.
MSTEST0012 AssemblyInitializeShouldBeValidAnalyzer A method marked with [AssemblyInitialize] should have valid layout.
MSTEST0013 AssemblyCleanupShouldBeValidAnalyzer A method marked with [AssemblyCleanup] should have valid layout.
MSTEST0014 DataRowShouldBeValidAnalyzer An instance of [DataRow] is not following one or multiple points of the required DataRow layout.
MSTEST0017 AssertionArgsShouldBePassedInCorrectOrder This rule raises an issue when calls to Assert.AreEqual, Assert.AreNotEqual, Assert.AreSame or Assert.AreNotSame are following one or multiple of the patterns below:

- actual argument is a constant or literal value
- actual argument variable starts with expected, _expected or Expected
- expected or notExpected argument
variable starts with actual
- actual is not a local variable
MSTEST0018 DynamicDataShouldBeValidAnalyzer A method marked with [DynamicData] should have valid layout.
MSTEST0023 DoNotNegateBooleanAssertionAnalyzer This rule raises a diagnostic when a call to Assert.IsTrue or Assert.IsFalse contains a negated argument.
MSTEST0024 DoNotStoreStaticTestContextAnalyzer This rule raises a diagnostic when an assignment to a static member of a TestContext parameter is done.
MSTEST0026 AssertionArgsShouldAvoidConditionalAccessRuleId This rule raises a diagnostic when an argument containing a null conditional operator (?.) or ?[] is passed to the assertion methods below:

- Assert.IsTrue
- Assert.IsFalse
- Assert.AreEqual
- Assert.AreNotEqual
- Assert.AreSame
- Assert.AreNotSame
- CollectionAssert.AreEqual
- CollectionAssert.AreNotEqual
- CollectionAssert.AreEquivalent
- CollectionAssert.AreNotEquivalent
- CollectionAssert.Contains
- CollectionAssert.DoesNotContain
- CollectionAssert.AllItemsAreNotNull
- CollectionAssert.AllItemsAreUnique
- CollectionAssert.AllItemsAreInstancesOfType
- CollectionAssert.IsSubsetOf
- CollectionAssert.IsNotSubsetOf
- StringAssert.Contains
- StringAssert.StartsWith
- StringAssert.EndsWith
- StringAssert.Matches
- StringAssert.DoesNotMatch
MSTEST0030 TypeContainingTestMethodShouldBeATestClass Type containing [TestMethod] should be marked with [TestClass], otherwise the test method will be silently ignored.
MSTEST0031 DoNotUseSystemDescriptionAttribute 'System.ComponentModel.DescriptionAttribute' has no effect in the context of tests.
MSTEST0032 ReviewAlwaysTrueAssertConditionAnalyzer This rule raises a diagnostic when a call to an assertion produces an always-true condition.
MSTEST0034 UseClassCleanupBehaviorEndOfClass This rule raises a diagnostic when ClassCleanupBehavior.EndOfClass isn't set with the [ClassCleanup].
MSTEST0035 UseDeploymentItemWithTestMethodOrTestClassTitle This rule raises a diagnostic when [DeploymentItem] isn't set on test class or test method.
MSTEST0037 UseProperAssertMethodsAnalyzer The use of Assert methods in a specific way when there is a better alternative.
MSTEST0038 AvoidAssertAreSameWithValueTypesAnalyzer The use of Assert.AreSame or Assert.AreNotSame with one or both arguments being a value type.
MSTEST0039 UseNewerAssertThrowsAnalyzer The use of Assert.ThrowsException or Assert.ThrowsExceptionAsync, which are no longer recommended.
MSTEST0040 AvoidUsingAssertsInAsyncVoidContextAnalyzer The use of any assertion method in an async void method, local function, or lambda.
MSTEST0041 UseConditionBaseWithTestClassAnalyzer The use of an attribute that inherits from ConditionBaseAttribute on a class that is not marked with TestClassAttribute.
MSTEST0042 DuplicateDataRowAnalyzer A test method has two or more DataRow attributes that are equivalent.
MSTEST0043 UseRetryWithTestMethodAnalyzer A method has an attribute that derives from RetryBaseAttribute and does not have an attribute that derives from TestMethodAttribute.
MSTEST0046 StringAssertToAssertAnalyzer A test method uses StringAssert methods instead of equivalent Assert methods.
MSTEST0048 TestContextPropertyUsageAnalyzer A fixture method (methods with AssemblyInitializeAttribute, AssemblyCleanupAttribute, ClassInitializeAttribute, or ClassCleanupAttribute) accesses restricted TestContext properties.
MSTEST0049 FlowTestContextCancellationTokenAnalyzer A method call within a test context doesn't use the CancellationToken available from TestContext when the called method has a parameter or overload that accepts a CancellationToken.
MSTEST0050 GlobalTestFixtureShouldBeValidAnalyzer A global test fixture method (marked with GlobalTestInitializeAttribute or GlobalTestCleanupAttribute) doesn't follow the required layout or has invalid configuration.