Skip to content

Commit

Permalink
S2699 Reproducer for AssertionMethodAttribute is ignored when asserti…
Browse files Browse the repository at this point in the history
…on method is inherited (#6528)

* Add test case for derived methods

* Add a test case for CustomAssertion on overridden method.

* Remove generics

* Remove sealed
  • Loading branch information
martin-strecker-sonarsource committed Dec 15, 2022
1 parent e27457c commit 2227150
Showing 1 changed file with 19 additions and 2 deletions.
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2227150

Please sign in to comment.