You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When testing a VB.NET project, VB.NET files where all classes or all members are attributed with the ExcludeFromCodeCoverage attribute are marked as uncovered by SonarScanner.
Repro steps
Create a VB.NET project with a file where all members are excluded from code coverage using the ExcludeFromCodeCoverage attribute.
Run SonarScanner with code coverage enabled using the steps as shown here. This happens no matter if the method in question is actually covered with tests or not.
This seems to only apply to VB.NET code where all the members are excluded, if I have a partially excluded file, ExcludeFromCodeCoverage works as intended. For example, this works fine:
Thank you for reporting this issue.
I was able to reproduce the issue.
I will add this ticket to the backlog so the team can fix it in the future.
The issue seems to come from the VisualBasicExecutableLinesMetric class.
I added some UT but I am not sure why it works as expected when only a few members of the module are excluded.
sebastien-marichal
changed the title
ExcludeFromCodeCoverage not working with VB.NET when full file is excluded
Executable line metric do not properly take into account ExcludeFromCodeCoverage attribute in VB.NET
Jan 22, 2024
Description
When testing a VB.NET project, VB.NET files where all classes or all members are attributed with the
ExcludeFromCodeCoverage
attribute are marked as uncovered by SonarScanner.Repro steps
Create a VB.NET project with a file where all members are excluded from code coverage using the
ExcludeFromCodeCoverage
attribute.For example:
or
Run SonarScanner with code coverage enabled using the steps as shown here. This happens no matter if the method in question is actually covered with tests or not.
This seems to only apply to VB.NET code where all the members are excluded, if I have a partially excluded file, ExcludeFromCodeCoverage works as intended. For example, this works fine:
The equivalent C# variants work for all of the mentioned code snippets.
Known workarounds
Use a file filter to exclude the files that should be excluded.
Related information
I have tested this with dotCover and coverlet.
The text was updated successfully, but these errors were encountered: