Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executable line metric do not properly take into account ExcludeFromCodeCoverage attribute in VB.NET #8523

Open
Goregius opened this issue Jan 9, 2024 · 1 comment
Labels
Area: VB.NET VB.NET rules related issues. Type: Coverage Improve code coverage handling.

Comments

@Goregius
Copy link

Goregius commented Jan 9, 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:

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.

@sebastien-marichal
Copy link
Contributor

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.

@sebastien-marichal sebastien-marichal added the Type: Bug Exceptions and blocking issues during analysis. label Jan 22, 2024
@sebastien-marichal 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
sebastien-marichal added a commit that referenced this issue Jan 23, 2024
sebastien-marichal added a commit that referenced this issue Jan 23, 2024
@Tim-Pohlmann Tim-Pohlmann added the Area: VB.NET VB.NET rules related issues. label Apr 9, 2024
@sebastien-marichal sebastien-marichal added Type: Coverage Improve code coverage handling. and removed Type: Bug Exceptions and blocking issues during analysis. labels Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: VB.NET VB.NET rules related issues. Type: Coverage Improve code coverage handling.
Projects
None yet
Development

No branches or pull requests

3 participants