How to mark custom methods as assertion methods in c#?

Hi there

I am the developer of bUnit, a testing library for Blazor components.

One of my users are reporting that the custom assertion methods I provide are not recognized as assertion methods, and causes the following lint error to be reported: https://rules.sonarsource.com/csharp/RSPEC-2699

Is there a way for me as a library author to give SonarLint a hint to get around this false-positive?

More context: https://github.com/egil/bUnit/discussions/216

Hi @egil,

Welcome to our community. The S2699 rule is mainly aware only of MSTest, NUnit and XUnit frameworks. It has no configuration nor customization capability, so it cannot be configured with SonarQube rule attributes nor by any kind of ThisIsAssertionMethodAttribute.

The detection of assertions is based on string comparation. If the method name contains any of these keywords (case insensitive), then it’s considered to be an assertion:

  • ASSERT
  • CHECK
  • EXPECT
  • MUST
  • SHOULD
  • VERIFY
  • VALIDATE
1 Like

hi @Pavel_Mikula

Thank you.

Is there any way to get the word Matches added to that list?

Please feel free to submit a New Issue here. Please add link to this thread for reference and some examples from your library.

We’ll need to discus this in the team due to Regex.Matches collision. We might came up with other solution as well.