Sonarqube error while parsing the visualstudio.coveragexml file


(Ruben Vilhena) #1

Must-share information (formatted with Markdown):

SonarScanner.MSBuild.exe begin /k:“Name” /n:“Name” /d:sonar.host.url=“http://url” /d:sonar.login=“login” /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\VisualStudio.coveragexml"

I have opened the file VisualStudio.coveragexml in Notepad and in a browser and it shows as a valid XML file.

Getting the error:
ERROR: Error during SonarQube Scanner execution
ERROR: Error while parsing the XML file: C:\Users\rv68115\Source\Workspaces\SSE.
ESIT\Dev\P0113 - Tender Manager\V1.1\VisualStudio.coveragexml
INFO: ------------------------------------------------------------------------
The SonarQube Scanner did not complete successfully
10:21:28.283 Creating a summary markdown file…
10:21:28.289 Post-processing failed. Exit code: 1

I have attached an image of the coverage file the file.

Thanks,
Ruben Vilhena


(Ruben Vilhena) #2

I have changed the encoding of the file to be UTF-8.
I got the following error now:

ERROR: Error during SonarQube Scanner execution
ERROR: Missing root element in C:\Users\rv68115\Source\Workspaces\SSE.
ESIT\Dev\P0113 - Tender Manager\V1.1\VisualStudio.coveragexml at line 1
ERROR:
The SonarQube Scanner did not complete successfully
11:42:16.417 Creating a summary markdown file…
11:42:16.425 Post-processing failed. Exit code: 1


(Duncan Pocklington) #3

Based on this issue raised against the vstest repo, I think the SonarSource docs no longer describe the approach recommended by Microsoft.

Does it work if you omit the command
"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output: **"%CD%\VisualStudio.coverage"**

and add the /enableCodeCoverage argument to the vstest.console.exe instead?

Duncan


(Ruben Vilhena) #4

Hi Duncan,

thanks. That helped.
I managed to run the scan with no errors.
But I don’t see any code coverage numbers added. And the percentage still remains at 0.0%.
If I import the Unit Tests, I managed to see 112 unit tests showing in the dashboards.

So my question is:

  • How is the Code Coverage Results reflected in the Dashboard? It is just at the %?

Looking at my coveragexml file it is showing some coverage that I don’t see reflected on the Dashboard.

I am using the command:
SonarScanner.MSBuild.exe begin /k:"ProjectName" /v:"1.2" /d:sonar.host.url="http://xx.xx.xx.x/sonar" /d:sonar.cs.vstest.reportsPaths="%CD%\TestResults\*.trx" /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\TestResults\Visual.coveragexml"

Thank you.
Ruben Vilhena


(Duncan Pocklington) #5

Hi Ruben,

You should see a percentage coverage figure on the dashboard. If you drill down to view the product code you will also see green and red bars showing which lines are covered, as in the screen shot below.

Trying running the analysis specifying /d:sonar.verbose=true on the command line to increase the logging level and look at the console output for the end step. If the import is working correctly you would expect to see output like the following:

13:23:38.857 INFO: Sensor C# Tests Coverage Report Import [csharp]
13:23:38.858 INFO: Parsing the Visual Studio coverage XML report d:\support\Scanner\coveragebug\ConsoleApp1\vs.coveragexml
13:23:38.861 INFO: Adding this code coverage report to the cache for later reuse: d:\support\Scanner\coveragebug\ConsoleApp1\vs.coveragexml
13:23:38.864 DEBUG: Found some coverage info for the file 'D:\support\Scanner\coveragebug\ConsoleApp1\ConsoleApp1\Program.cs'.
13:23:38.865 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=8ms

Duncan


(Ruben Vilhena) #6

Hi Duncan,

I added the verbose options but don’t get that result:
13:42:41.007 INFO: Sensor C# Tests Coverage Report Import [csharp]
13:42:41.010 INFO: Parsing the Visual Studio coverage XML report C:\Users\rv6811
5\Source\Workspaces\SSE.ESIT\Dev\P0113 - Tender Manager\V1.1\TestResults\VisualS
tudio.coveragexml
13:42:41.267 INFO: Adding this code coverage report to the cache for later reuse
: C:\Users\rv68115\Source\Workspaces\SSE.ESIT\Dev\P0113 - Tender Manager\V1.1\Te
stResults\VisualStudio.coveragexml
13:42:41.267 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time
=260ms

Also I can’t see any green bars, just red.

image

Thanks,
Ruben


(Duncan Pocklington) #7

That suggests the C# test sensor can’t match any of the files listed in the coverage XML to product files it has analyzed. Could you double-check that the coverage file contains information about product files appear in SonarQube? (the coverage file may contain coverage information about test files too, but that coverage information will not be uploaded).

Also, can you repro this with a small solution that you are able to share?
I tried it locally and the coverage data was uploaded as expected.

[Update: BTW I’ve update our documentation to reflect the Mircosoft recommendations]

Thanks,
Duncan


(Ruben Vilhena) #8

Hi Duncan,

I have tried to follow your approach and achieved some success.

My end goal is to load the test coverage into a SonarQube 7.6 installation I have on a server that is being used by my dev team.

To follow your recommendation I tried to import the code coverage results for a smaller project but in my local SonarQube installation.

I managed to get Cove Coverage % loaded and see them in the dashboards.

After that I tried the same with my initial project again on my local machine. And I have managed to get the results imported.

The problem is when I repeat the process on the server the results don’t get imported.

I even tried to create the project again in SonarQube but with the same result in the end.

The only differences I found are:

  • my local version is a Developer Edition (because I am trying the PL/SQL code analyser)
  • my server version has a configured url instead of the default - http://localhost:9000

Would any of these make a difference?

Thanks,
Ruben


(Ruben Vilhena) #9

Finally got it working on the server.

It only worked after I restarted SonarQube.

Not sure when this should have been done. But that was the final step that made it work.