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 |
MSTEST0023 | DoNotNegateBooleanAssertionAnalyzer | Do not negate boolean assertions |
MSTEST0024 | DoNotStoreStaticTestContextAnalyzer | Do not store TestContext in a static member |
MSTEST0026 | AssertionArgsShouldAvoidConditionalAccessRuleId | Avoid conditional access in assertions |
MSTEST0037 | UseProperAssertMethodsAnalyzer | Use proper Assert methods |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.