SonarCloud Msbuild Code OpenCover coverage issue

Hi,
i cannot get Code Coverage working for Sonar Cloud.
It looks like opencover.xml and UnitTest.trx are created correctly and uploaded to cloud, but is see no changes on the web.

Thanks for help!
Jakub K.

  • versions used is SonarCloud MSBuild 5.0.4.24009 fw 4.6

  • error observed : NO Code coverage changes on the sonarcloud.io website

  • steps to reproduce
    BUILD PROJECT: "c:\jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\SonarScannerFW4.6MS410\SonarScanner. MSBuild.exe" begin /k:XXX /o:oneidentity /d:“sonar.branch.name=topic-sonar-code-coverage” /d:sonar.skipPackageDesign=true /d:sonar.showProfiling=true /d:sonar.log.level=TRACE /d:sonar.verbose=true /d:"sonar.login=" /d:"sonar.exclusions=/.g.cs,/*.resx,/*json,/js,/*tpl,/srt,/*cbt,/loc,/*cfg,/snippet,/*tss,/ico,/*png,/sql,**/.Designer.cs,/_AutoGenerated/,/DataHub/,/escrow/" /d:sonar.c.file.suffixes=- /d:sonar.cpp.file.suffixes=- /d:sonar.objc.file.suffixes = - **/d:sonar.cs.vstest.reportsPaths=**.trx** / **d:sonar.cs.opencover.reportsPaths=*\opencover.xml

    RUN UNIT TESTS: c:\jenkins\workspace\peline_topic-sonar-code-coverage>C:\Users\XXX.nuget\packages\opencover\4.7.922\tools\ OpenCover.Console.exe -output:"c:\jenkins\workspace\peline_topic-sonar-code-coverage\src\opencover.xml " -register -target:“C:\Program Files\dotnet\dotnet.exe” -targetargs:"vstest c:\jenkins\workspace\peline_topic-sonar-code-coverage\src\XXX\bin\Release\x64\ XXX.dll –logger:“trx;LogFileName=c:\jenkins\workspace\peline_topic-sonar-code-coverage\src\UnitTest.trx”"
    ….
    Results File: c:\jenkins\workspace\peline_topic-sonar-code-coverage\src\UnitTest.trx
    Test Run Successful. Total tests: 347 Passed: 345 Skipped: 2
    ……
    DEBUG: Pattern matcher extracted prefix/absolute path ‘c:\jenkins\workspace\peline_topic-sonar-code-coverage\src.’ from the given pattern '*\opencover.xml’.*
    DEBUG: Gathering files for wildcardPattern ‘**\opencover.xml’.
    DEBUG: Pattern matcher returns ‘1’ files.
    DEBUG: The current user dir is ‘c:\jenkins\workspace\peline_topic-sonar-code-coverage\src’.
    INFO: Parsing the OpenCover report c:\jenkins\workspace\peline_topic-sonar-code-coverage\src.\opencover.xml
    ….
    DEBUG: Skipping the file (ID ‘380’, path ‘C:\Dev\xunit\xunit\src\xunit.runner.utility\Runners\TestStartingInfo.cs’, NO INDEXED PATH), line ‘17’, visitCount ‘0’ because file is not indexed or does not have the supported language
    ….
    DEBUG: CoveredFile created: (ID ‘595’, path ‘T:\XXXUnitTests\UnitTestHelper.cs’, indexed as ‘T:\XXXUnitTests\UnitTestHelper.cs’).
    DEBUG: CoveredFile created: (ID ‘779’, path ‘T:\XXXWorkflow\WorkflowEngine\BaseItem.cs’, indexed as ‘T:\XXXWorkflow\WorkflowEngine\BaseItem.cs’)
    ….
    INFO: Coverage Report Statistics: 242 files, 202 main files, 202 main files with coverage, 40 test files, 0 project excluded files, 0 other language files.
    INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=14175ms
    INFO: Sensor C# Unit Test Results Import [csharp]
    DEBUG: Pattern matcher extracted prefix/absolute path ‘c:\jenkins\workspace\peline_topic-sonar-code-coverage\src.’ from the given pattern '**.trx’.*
    DEBUG: Gathering files for wildcardPattern '*.trx’.**
    DEBUG: Pattern matcher returns ‘1’ files.
    DEBUG: The current user dir is ‘c:\jenkins\workspace\peline_topic-sonar-code-coverage\src’.
    INFO: Parsing the Visual Studio Test Results file ‘c:\jenkins\workspace\peline_topic-sonar-code-coverage\src.\UnitTest.trx’.
    DEBUG: Parsed Visual Studio Test Times - duration: 81715.
    DEBUG: Parsed Visual Studio Test Counters - total: 347, failed: 0, errors: 0, timeout: 0, aborted: 0, executed: 345.
    INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=13207ms
    INFO: Sensor Zero Coverage Sensor
    INFO: Sensor Zero Coverage Sensor (done) | time=11752ms

    INFO: Analysis report generated in 15497ms, dir size=31 MB
    INFO: Analysis report compressed in 25791ms, zip size=20 MB
    INFO: Analysis report generated in c:\jenkins\workspace\peline_topic-sonar-code-coverage\src.sonarqube\out.sonar\scanner-report
    DEBUG: Upload report
    DEBUG: POST 200 https://sonarcloud.io/api/ce/submit?organization=oneidentity&projectKey=XXX&characteristic=branch%3Dtopic-sonar-code-coverage&characteristic=branchType%3DSHORT | time=4187ms
    INFO: Analysis report uploaded in 4189ms
    DEBUG: GET 200 https://sonarcloud.io/api/server/version | time=163ms
    DEBUG: Report metadata written to c:\jenkins\workspace\peline_topic-sonar-code-coverage\src.sonarqube\out.sonar\report-task.txt
    INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=XXX&branch=topic-sonar-code-coverage&resolved=false
    INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
    INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AXhbpy7_RC00k5BgmsVD
    DEBUG: Post-jobs :
    INFO: Analysis total time: 15:53.513 s
    INFO: ------------------------------------------------------------------------
    INFO: EXECUTION SUCCESS
    INFO: ------------------------------------------------------------------------
    INFO: Total time: 16:32.825s
    INFO: Final Memory: 34M/140M
    INFO: ------------------------------------------------------------------------
    Process returned exit code 0
    The SonarScanner CLI has finished
    20:36:32.658 Post-processing succeeded.
    Started: 20:19:43.78
    Stopped: 20:36:32.69
    Elapsed: 1008.91 seconds

I have been struggling with this exact issue, using Azure DevOps, the last couple of days.

The .trx files seem to be processed as it shows 323 unit tests on our dashboard, the coverage percentage however stays at 0.0%.

In the logs I saw:
ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=XXX&pullRequest=XXX

Following that link leads me to the quality gate and there it shows:

However, even when the PR is merged, no difference on the dashboard.

I was confused about when the project overview report was updated. Turns out I was running the analysis only against my PR builds and not the builds on our master branch. Running against the master branch updated the code coverage % for us.

2 Likes

hi @J_K

did you read [Coverage] Troubleshooting guide for .NET code coverage import?

Hi, after merge to Master the Code Coverage appear too.

Thank you!.
Regards Jakub.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.