Is it possible to import OpenCover /result in SonarQube?

Nicholas picture Nicholas · Oct 23, 2014 · Viewed 8k times · Source

I'm currently changing things to our Sonar setup since Gallio isn't supported anymore by C# Ecosystem 3. I already successfully imported the unit test coverage by using OpenCover with following command.

"C:\Program Files (x86)\OpenCover\OpenCover.Console.exe" -register -target:"c:\Program Files (x86)\NUnit 2.6.3\bin\nunit-console-x86.exe" -targetargs:"d:\Sonar\MyTest.dll /noshadow /framework=net-4.0" -output:"d:\Deploy\Sonar\Coverage.xml" "-filter:+[*]* -[*]Test"

With this command I'm only getting the Unit Test Coverage but I would also like to see the number of failed and successful tests. I think I can achieve this with the /result option like

"C:\Program Files (x86)\OpenCover\OpenCover.Console.exe" -register -target:"c:\Program Files (x86)\NUnit 2.6.3\bin\nunit-console-x86.exe" -targetargs:"d:\Deploy\Sonar\MyTest.dll /noshadow /framework=net-4.0 /result=tests.xml"

This command returns an xml with information about the tests that ran but is there any way to import this xml into SonarQube? Or isn't this supported?

Currently I'm importing the Coverage.xml file with the following command:

sonar.cs.opencover.reportsPaths=D:/Deploy/Sonar/Coverage.xml

Is there a similar property to import the tests.xml file with the test results?

Answer

Paul Kertscher picture Paul Kertscher · Oct 24, 2017

OpenCover is now officially supported by SonarQube, please see the SonarQube documentation. You can pass the location of the XML report OpenCover generated with the command line parameter

/d:sonar.cs.opencover.reportsPaths="%path%\%report_file%"

where %path% is the folder your report file is generated in and %report_file% is the file name of your OpenCover XML report.