MSTest usage rules
Rules that support proper usage of MSTest.
Identifier | Name | Description |
---|---|---|
MSTEST0002 | TestClassShouldBeValidAnalyzer | Test classes, classes marked with the [TestClass] attribute, should respect the following layout to be considered valid by MSTest: - it should be public (or internal if [assembly: DiscoverInternals] attribute is set)- it should not be static - it should not be generic. |
MSTEST0003 | TestMethodShouldBeValidAnalyzer | Test methods, methods marked with the [TestMethod] attribute, should respect the following layout to be considered valid by MSTest:- it should be public (or internal if [assembly: DiscoverInternals] attribute is set)- it should not be static - it should not be generic - it should not be abstract - return type should be void or Task - it should not be async void - it should not be a special method (for example, finalizer or operator). |
MSTEST0005 | TestContextShouldBeValidAnalyzer | TestContext property should follow the following layout to be valid: - it should be a property - it should be public (or internal if [assembly: DiscoverInternals] attribute is set)- it should not be static - it should not be readonly. |
MSTEST0007 | UseAttributeOnTestMethodAnalyzer | The following test attributes should only be applied on methods marked with the TestMethodAttribute attribute: - [CssIteration] - [CssProjectStructure] - [Description] - [ExpectedException] - [Owner] - [Priority] - [TestProperty] - [WorkItem] |
MSTEST0008 | TestInitializeShouldBeValidAnalyzer | Methods marked with [TestInitialize] should follow the following layout to be valid:- it should be public - it should not be static - it should not be generic - it should not be abstract - it should not take any parameter - return type should be void , Task or ValueTask - it should not be async void - it should not be a special method (finalizer, operator...). |
MSTEST0009 | TestCleanupShouldBeValidAnalyzer | Methods marked with [TestCleanup] should follow the following layout to be valid:- it should be public - it should not be static - it should not be generic - it should not be abstract - it should not take any parameter - return type should be void , Task or ValueTask - it should not be async void - it should not be a special method (finalizer, operator...). |
MSTEST0010 | ClassInitializeShouldBeValidAnalyzer | Methods marked with [ClassInitialize] should follow the following layout to be valid:- it should be public - it should be static - it should not be generic - it should take one parameter of type TestContext - return type should be void , Task or ValueTask - it should not be async void - it should not be a special method (finalizer, operator...). |
MSTEST0011 | ClassCleanupShouldBeValidAnalyzer | Methods marked with [ClassCleanup] should follow the following layout to be valid:- it should be public - it should be static - it should not be generic - it should not take any parameter - return type should be void , Task or ValueTask - it should not be async void - it should not be a special method (finalizer, operator...). |
MSTEST0012 | AssemblyInitializeShouldBeValidAnalyzer | Methods marked with [AssemblyInitialize] should follow the following layout to be valid:- it should be public - it should be static - it should not be generic - it should take one parameter of type TestContext - return type should be void , Task or ValueTask - it should not be async void - it should not be a special method (finalizer, operator...). |
MSTEST0013 | AssemblyCleanupShouldBeValidAnalyzer | Methods marked with [AssemblyCleanup] should follow the following layout to be valid:- it should be public - it should be static - it should not be generic - it should not take any parameter - return type should be void , Task or ValueTask - it should not be async void - it should not be a special method (finalizer, operator...). |
MSTEST0014 | DataRowShouldBeValidAnalyzer | [DataRow] instances should have the following layout to be valid:- they should only be set on a test method - argument count should match method parameters count - argument type should match method argument type |
MSTEST0017 | AssertionArgsShouldBePassedInCorrectOrder | Assertion arguments should be passed in the correct order |
MSTEST0018 | DynamicDataShouldBeValidAnalyzer | Methods marked with [DynamicData] should also be marked with [TestMethod] (or a derived attribute) |
MSTEST0023 | DoNotNegateBooleanAssertionAnalyzer | Do not negate boolean assertions |
MSTEST0024 | DoNotStoreStaticTestContextAnalyzer | Do not store TestContext in a static member |
MSTEST0026 | AssertionArgsShouldAvoidConditionalAccessRuleId | Avoid conditional access in assertions |
MSTEST0030 | TypeContainingTestMethodShouldBeATestClass | Type containing [TestMethod] should be marked with [TestClass] |
MSTEST0031 | DoNotUseSystemDescriptionAttribute | 'System.ComponentModel.DescriptionAttribute' has no effect in the context of tests |
MSTEST0032 | ReviewAlwaysTrueAssertConditionAnalyzer | Review or remove the assertion as its condition is known to be always true |
MSTEST0034 | UseClassCleanupBehaviorEndOfClass | Use ClassCleanupBehavior.EndOfClass with the [ClassCleanup] |
MSTEST0035 | UseDeploymentItemWithTestMethodOrTestClassTitle | [DeploymentItem] can be specified only on test class or test method |
MSTEST0037 | UseProperAssertMethodsAnalyzer | Use proper Assert methods |
MSTEST0038 | AvoidAssertAreSameWithValueTypesAnalyzer | Don't use Assert.AreSame or Assert.AreNotSame with value types |
MSTEST0039 | UseNewerAssertThrowsAnalyzer | Use newer 'Assert.Throws' methods |
MSTEST0040 | AvoidUsingAssertsInAsyncVoidContextAnalyzer | Do not assert inside 'async void' contexts |
MSTEST0041 | UseConditionBaseWithTestClassAnalyzer | Use 'ConditionBaseAttribute' on test classes |
ทํางานร่วมกับเราใน GitHub
แหล่งที่มาสำหรับเนื้อหานี้สามารถพบได้บน GitHub ซึ่งคุณยังสามารถสร้างและตรวจสอบปัญหาและคำขอดึงข้อมูลได้ สำหรับข้อมูลเพิ่มเติม ให้ดูคู่มือผู้สนับสนุนของเรา