diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TestMethodShouldContainAssertion.Custom.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TestMethodShouldContainAssertion.Custom.cs index 2aa8bb44138..982c4c2dc55 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TestMethodShouldContainAssertion.Custom.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/TestMethodShouldContainAssertion.Custom.cs @@ -7,11 +7,14 @@ namespace CustomTests using TestFramework.Attributes; [TestClass] - public class Program + public class BaseTest { + [AssertionMethod] + protected virtual void CustomAssertionMethod() { } + [TestMethod] public void TestMethod1() // Noncompliant {{Add at least one assertion to this test case.}} -// ^^^^^^^^^^^ + // ^^^^^^^^^^^ { var x = 42; } @@ -56,6 +59,20 @@ public class Program var x = 42; } } + + [TestClass] + public class DerivedTest : BaseTest + { + [TestMethod] + public void Derived() // Noncompliant FP: The overridden method needs to be annotated because Roslyn does not respect AttributeUsage.Inherited in ISymbol.GetAttributes + { + CustomAssertionMethod(); + } + + protected override void CustomAssertionMethod() + { + } + } } namespace TestFramework