支援適當使用 MSTest 的規則。
| Identifier | Name | Description |
|---|---|---|
| MSTEST0002 | TestClassShouldBeValidAnalyzer | 測試類別未遵循必要的測試類別佈局中的一個或多個要點。 |
| MSTEST0003 | TestMethodShouldBeValidAnalyzer | 測試方法未遵循所需測試方法配置的單一或多個點。 |
| MSTEST0005 | TestContextShouldBeValidAnalyzer | 測試內容屬性未遵循所需測試內容配置的單一或多個點。 |
| MSTEST0007 | UseAttributeOnTestMethodAnalyzer | 未標示 TestMethodAttribute 的方法已套用一或多個測試屬性。 |
| MSTEST0008 | TestInitializeShouldBeValidAnalyzer | 標記為 [TestInitialize] 的方法應該具有有效配置。 |
| MSTEST0009 | TestCleanupShouldBeValidAnalyzer | 標記為 [TestCleanup] 的方法應該具有有效配置。 |
| MSTEST0010 | ClassInitializeShouldBeValidAnalyzer | 標記為 [ClassInitialize] 的方法應該具有有效配置。 |
| MSTEST0011 | ClassCleanupShouldBeValidAnalyzer | 標記為 [ClassCleanup] 的方法應該具有有效配置。 |
| MSTEST0012 | AssemblyInitializeShouldBeValidAnalyzer | 標記為 [AssemblyInitialize] 的方法應該具有有效配置。 |
| MSTEST0013 | AssemblyCleanupShouldBeValidAnalyzer | 標記為 [AssemblyCleanup] 的方法應該具有有效配置。 |
| MSTEST0014 | DataRowShouldBeValidAnalyzer |
[DataRow] 的一個執行個體未遵循所需 DataRow 配置的一個或多個點。 |
| MSTEST0017 | AssertionArgsShouldBePassedInCorrectOrder | 對 Assert.AreEqual、Assert.AreNotEqual、Assert.AreSame 或 Assert.AreNotSame 的呼叫遵循下列一或多個模式時,此規則會引發問題:- actual 自變數是常數或常值- actual 自變數變數開頭為 expected、 _expected 或 Expected- expected 或 notExpected 自變數 變數開頭為 actual- actual 不是局部變數 |
| MSTEST0018 | DynamicDataShouldBeValidAnalyzer | 標記為 [DynamicData] 的方法應該具有有效配置。 |
| MSTEST0023 | DoNotNegateBooleanAssertionAnalyzer | 對 Assert.IsTrue 或 Assert.IsFalse 的呼叫包含否定引數時,此規則會引發診斷。 |
| MSTEST0024 | DoNotStoreStaticTestContextAnalyzer | 當指派給 static 參數的 TestContext 成員時,此規則會引發診斷。 |
| MSTEST0026 | AssertionArgsShouldAvoidConditionalAccessRuleId | 當包含 null 條件運算子(?.) 或 ?[] 的引數傳遞至以下判斷提示方法時,此規則會引發診斷:- 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 | 包含 [TestMethod] 的類型應標示為 [TestClass],否則會以無訊息方式忽略測試方法。 |
| MSTEST0031 | DoNotUseSystemDescriptionAttribute | 'System.ComponentModel.DescriptionAttribute' 在測試的內容中沒有效果。 |
| MSTEST0032 | ReviewAlwaysTrueAssertConditionAnalyzer | 在呼叫判斷提示時若產生始終為 true 狀況,此規則會引發診斷。 |
| MSTEST0034 | UseClassCleanupBehaviorEndOfClass | 未使用 ClassCleanupBehavior.EndOfClass 設定 [ClassCleanup] 時,此規則會引發診斷。 |
| MSTEST0035 | UseDeploymentItemWithTestMethodOrTestClassTitle | 當測試類別或測試方法上未設定 [DeploymentItem] 時,此規則會引發診斷。 |
| MSTEST0037 | UseProperAssertMethodsAnalyzer | 當有更好的替代方案時,以特定方式使用 Assert 方法。 |
| MSTEST0038 | AvoidAssertAreSameWithValueTypesAnalyzer | 使用 Assert.AreSame 或 Assert.AreNotSame,其中一或兩個引數都是值類型。 |
| MSTEST0039 | UseNewerAssertThrowsAnalyzer | 不再建議使用 Assert.ThrowsException 或 Assert.ThrowsExceptionAsync。 |
| MSTEST0040 | AvoidUsingAssertsInAsyncVoidContextAnalyzer | 在 async void 方法、本機函式或 Lambda 中使用任何斷言方法。 |
| MSTEST0041 | UseConditionBaseWithTestClassAnalyzer | 在未標記為ConditionBaseAttribute的類別上使用繼承自 TestClassAttribute 的屬性。 |
| MSTEST0042 | DuplicateDataRowAnalyzer | 測試方法具有兩個或多個相等 的 DataRow 屬性。 |
| MSTEST0043 | UseRetryWithTestMethodAnalyzer | 方法具有衍生自 RetryBaseAttribute 的屬性,而且沒有衍生自 TestMethodAttribute的屬性。 |
| MSTEST0046 | StringAssertToAssertAnalyzer | 測試方法會使用 StringAssert 方法,而不是對等 Assert 的方法。 |
| MSTEST0048 | TestContextPropertyUsageAnalyzer | 裝置方法(具有 AssemblyInitializeAttribute、 AssemblyCleanupAttribute、 ClassInitializeAttribute或 ClassCleanupAttribute的方法)會存取受限制 TestContext 的屬性。 |
| MSTEST0049 | FlowTestContextCancellationTokenAnalyzer(流程測試上下文取消令牌分析器) | 當呼叫的方法具有接受 CancellationToken的參數或多載時,測試上下文中的方法呼叫不會使用從 TestContext 可用的 CancellationToken。 |
| MSTEST0050 | GlobalTestFixtureShouldBeValidAnalyzer | 全域測試裝置方法(使用 GlobalTestInitializeAttribute 或 GlobalTestCleanupAttribute 標示)未遵循必要的佈局或設定無效。 |
| MSTEST0051 | AssertThrowsShouldContainSingleStatementAnalyzer | 對 Throws、 、 ThrowsAsyncThrowsExactly或 ThrowsExactlyAsync 的呼叫包含動作委派中的多個陳述式。 |
| MSTEST0052 | 避免顯式動態數據源類型分析器 | A DynamicDataAttribute 明確指定 Property 或 Method 而不是使用預設 AutoDetect。 |
| MSTEST0053 | AvoidAssertFormatParametersAnalyzer | 斷言方法呼叫會使用 message 和 parameters 引數來設定字串格式,而不是使用字串插補。 |
| MSTEST0054 | UseCancellationTokenPropertyAnalyzer | 通過 CancellationToken 訪問 TestContext.CancellationTokenSource.Token 而不是使用 TestContext.CancellationToken 屬性。 |
| MSTEST0055 | IgnoreStringMethodReturnValueAnalyzer |
string.Contains、string.StartsWith或string.EndsWith被呼叫,其傳回值被忽略。 |