Executable line metric do not properly take into account ExcludeFromCodeCoverage attribute in VB.NET
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:
Imports System.Diagnostics.CodeAnalysis
<ExcludeFromCodeCoverage>
Public Module Class1
Public Sub TestMe()
Console.WriteLine("Exclude me")
End Sub
End Module
or
Imports System.Diagnostics.CodeAnalysis
Public Module Class1
<ExcludeFromCodeCoverage>
Public Sub TestMe()
Console.WriteLine("Exclude me")
End Sub
End Module
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:
Public Module Class2
<ExcludeFromCodeCoverage>
Public Sub TestMe()
Console.WriteLine("Exclude me")
End Sub
Public Sub TestMe2()
Console.WriteLine("Exclude me")
End Sub
End Module
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
- C#/VB.NET Plugins version 9.8.0.76515
- Visual Studio version 17.8.0
- MSBuild / dotnet version 4.7.2 and 8
- Operating System Windows 10
I have tested this with dotCover and coverlet.
Hello @Goregius,
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.
Moved to NET-1631