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

Code coverage report is not generated for some methods #3191

Closed
pavel-mikula-sonarsource opened this issue Mar 9, 2020 · 6 comments
Closed
Assignees
Labels
Area: SQ Plugin Java plugin related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: Coverage Improve code coverage handling.

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

pavel-mikula-sonarsource commented Mar 9, 2020

Description

VSTest.console.exe does not include covered methods into report file. Not even as 0% covered. Theese methods are not seen by SC as covered and QG fails.

Methods

  • SonarAnalyzer.Helpers.StringExtensions.SplitCamelCaseToWords
  • SonarAnalyzer.Helpers.SymbolHelper.GetAllNamedTypes

Other

  • Renaming file, class and method to OtherFileName.SplitCamelCaseTxWords reproduces the issue.
  • Adding second method into file forces it to work as expected with 100% coverage.
  • VS Enteprise is needed for local run of VSTest.console /EnableCodeCoverage
  • Might be related to yield iterators (see this comment)
@andrei-epure-sonarsource
Copy link
Contributor

maybe linked to https://community.sonarsource.com/t/adding-another-test-run-halves-the-code-coverage/15087/16 , there are some reproducers there as well

@costin-zaharia-sonarsource costin-zaharia-sonarsource removed this from the 8.6 milestone Apr 1, 2020
@andrei-epure-sonarsource
Copy link
Contributor

From what we've discussed, we should:

  • double check that the coverage info doesn't get generated by the vscover tool
  • come up with a reproducer project
  • report the issue to vstest

unless we realize there's a parsing error on our side

@pavel-mikula-sonarsource pavel-mikula-sonarsource removed the Type: Tooling Tools make us productive. label Jun 25, 2021
@Tim-Pohlmann
Copy link
Contributor

Tim-Pohlmann commented May 29, 2024

  1. I recreated the issue by creating a test solution with only two projects:
  • .NET 8 Class library
  • .NET 8 MS Test project
    • contains a single UT calling "thisIsAName".SplitCamelCaseToWords().ToList().
  1. Run local SQ 10.5.1.90531 Enterprise
  2. dotnet sonarscanner begin /k:"Local-Sandbox" /d:sonar.host.url="http://localhost:9000" /d:sonar.token="<token>" /d:sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml
  3. dotnet build
  4. dotnet test --collect "Code Coverage;Format=xml"
  5. dotnet sonarscanner end /d:sonar.token="<token>"

A possible cause is how yield methods are reported in the .xml file:

<function block_coverage="82,22" line_coverage="70,59" blocks_covered="37" blocks_not_covered="8" lines_covered="24" lines_partially_covered="0" lines_not_covered="10" id="8360" token="0x6000005" name="MoveNext()" namespace="SonarAnalyzer.Helpers" type_name="StringExtensions.&lt;SplitCamelCaseToWords&gt;d__0">

Note that the method name is MoveNext() and not SplitCamelCaseToWords().

@mary-georgiou-sonarsource
Copy link
Contributor

mary-georgiou-sonarsource commented Jul 25, 2024

I tried Tim's repro but it does not work for me.
If I copy and paste exactly these commands, there are no coverage results because the file pattern cannot be found for some reason :/. Once I set the pattern to be any XML file, then coverage is normally found and reported.
Additionally, opening the coverage file, I can see the method SplitCamelCaseToWords is there.

@costin-zaharia-sonarsource do you have maybe any advice which direction I can go here?

@costin-zaharia-sonarsource
Copy link
Member

I think this might depend on the versions of the dotnet runtime and of the coverage tool. How about Pavel's example? Is the issue still reproducible when analyzing out code?

@mary-georgiou-sonarsource
Copy link
Contributor

mary-georgiou-sonarsource commented Jul 29, 2024

I cannot reproduce this.
Additionally, both methods mentioned in the issue description
SonarAnalyzer.Helpers.StringExtensions.SplitCamelCaseToWords
SonarAnalyzer.Helpers.SymbolHelper.GetAllNamedTypes (now refactored to be INamedTypeSymbolExtensions.GetAllNamedTypes)
seem to both be covered on SC (see here and here).

@mary-georgiou-sonarsource mary-georgiou-sonarsource closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource removed this from the 9.31 milestone Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: SQ Plugin Java plugin related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: Coverage Improve code coverage handling.
Projects
None yet
Development

No branches or pull requests

5 participants