Are the Assertions made in unit tests used for determining coverage percent?

If I have a unit test that has no assertions and throws no exceptions, are the paths in the target code that test exercises considered as Covered or Not Covered?

Hi @StingyJack

I think yes. Have you made the test yourself ?

No, I wouldnt write a test like that without leaving a reason why as a comment. These tests were inherited. Sonarcloud is reporting > 30% coverage for the repo and it looked strange considering there arent that many tests and they were mostly swallowing exceptions and lacked assertions.

I’m not asking for any Sonar secrets to be divulged here, but my observation is that assertions are not checked, and only the overall test result is used to deem all paths that test executes as “covered”. Is this something you can confirm or dispute, for the record?

You will normally get an issue raised when your test doesn’t have any assertions (should your test files be part of the analysis itself). I think as long as the line is called by the test, this is marked as covered.

Whats the rule number for tests without assertions? I’m having trouble finding it.

Nvm, found it (csharpsquid:S2699)

1 Like