sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

S2187: FP when Test methods are declared in nested types

Open costin-zaharia-sonarsource opened this issue 2 years ago • 0 comments

Description

Rule S2187, is raising a false positive when Test methods are declared in nested types

Repro steps

    [TestFixture]
    public class A // Noncompliant, FP - In NUnit this scenario is valid.
    {
        public class Nested : A
        {
            [Test]
            public void Test()
            {
            }
        }
    }

Expected behavior

The issue should not be raised.

Actual behavior

S2187 is raised.

Known workarounds

Declare the attribute on the nested type. This might be inconvenient when there are multiple nested types.

Related information

  • C#/VB.NET Plugins version: 8.40