I'm trying to disable a code analysis rule across an entire class, but NOT for the entire project, just a single class. In the example below, the build generates a CA1822 warning because it thinks that the unit test methods should be static.
The fix is to add the following attribute to each unit test method:
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
However, that's cumbersome and clutters a class with many unit tests.
I've tried:
- Moving the attribute to the class
- Wrapping all of the methods in
#pragma warning disable CA1822
#pragma warning restore CA1822
Neither of these two approaches have worked.
public class TestClass
{
public TestClass()
{
// some setup here
}
[Fact]
public void My_Unit_Test1()
{
// the 'this' parameter is never used, causes CA warning 1822
}
[Fact]
public void My_Unit_Test2()
{
// the 'this' parameter is never used, causes CA warning 1822
}
}
Using VS2015 Update 2, .net 4.61, and the new Code Analysis Analyzers.