Rule 2699 should recognize domain specific assertion methods as assertion methods as well.
In my particular case, my Blazor testing library bUnit has a semantic HTML comparer exposed as the as the assertion method MarkupMatches(...) which is not recognized as a assertion method by SonarLint.
A simple suggestion would be to add the word MATCHES to the assertion method list. But that is a quick-fix for this particular case, and will likely exclude other domain specific assertion methods in the future, so perhaps an attribute is a safer approach, for those that want to be compatible with SonarLint?
Simple example from the documentation link above:
// arrange
using var ctx = new TestContext();
// act
var cut = ctx.RenderComponent<Heading>();
// assert
cut.MarkupMatches(@"<h3 id=""heading-1337"" required>
Heading text
<small class=""mark text-muted"">Secondary text</small>
</h3>");
MarkupMatches to be recognized as an assertion method
MarkupMatches is not recognized as an assertion method.
Create another extension method that uses one of the keywords that is recognized as assertion statements.
Discussed here: https://community.sonarsource.com/t/how-to-mark-custom-methods-as-assertion-methods-in-c/31437
Not sure about these, maybe @domn1995 can help out, since he reported the problem originally: https://github.com/egil/bUnit/discussions/216
Hi @egil,
Thank you for taking the time to report this. We had a short discussion and we'll introduce some kind of attribute to enable marking methods as assertions.
Great, thanks. @andrei-epure-sonarsource / @pavel-mikula-sonarsource :
Please make it so that I can just create the attribute locally in the right namespace in my own library, so I do not have to take an unnecessary dependency on a 3rd party package.
@egil The proposal only checks the attribute name. It can be in any namespace of any assembly.
The update was merged to master and will be released with next Analyzer for C# 8.14 to SonarCloud and to the next release of SonarQube 8.6
@egil You can get your codebase ready according to new S2699 specification.
Thanks, ill add that to my todo list :)
Hi @pavel-mikula-sonarsource, can I get you to give this PR a very quick look and see if I am doing it right: https://github.com/egil/bUnit/pull/229
Most helpful comment
Hi @egil,
Thank you for taking the time to report this. We had a short discussion and we'll introduce some kind of attribute to enable marking methods as assertions.