Add an easy way to increase analyzer severity for rules that are good default, but a breaking change #3325
Description
Summary
MSTest v3 ships with a set of analyzers which are balanced to avoid braking changes.
Add a way to increase the severity of such rules for new projects so they can start with stricter rule set.
Get Warning for the case above, and use the recommended solution of making the class abstract when it is just a base class.
Background and Motivation
As an example: MSTEST0030, which reports info
on non-abstract test class that has [TestMethod]
but is not decorated with [TestClass]
. This leads to the TestMethod1 being skipped by the test framework.
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
The rule cannot be set to warning
by default, because this is also a common pattern to create a base class with tests that are inherited, but are not intended to run. A recommended solution for this case is to mark the class abstract.
In my test base I would like this rule, and other such rules to be warnings for any new project, without breaking my old projects that also use mstest v3.
Proposed Feature
Add build property or other knob to enable more strict analyzer rules for new projects, and make this the default in dotnet new templates, so new projects start with stricter rules, because they are more likely to embrace our recommended fixes and workarounds.
Possibly take advantage of analysis level https://learn.microsoft.com/dotnet/fundamentals/code-analysis/overview?tabs=net-8#enable-additional-rules