I am using TeamCity 8.0.4 and SonarQube 4.3
I am trying to get test coverage results in SonarQube for a C# project.
TeamCity runs dotCover analysis as part of MSTest build step.
The code coverage summary appears in the TeamCity build overview, but I'm not sure how to transmit this data to Sonar
The Sonar C# plugin accept the parameter:
(see here: http://docs.codehaus.org/display/SONAR/C%23+Plugin under the code coverage section)
but I can see in the logs that the dotCover report is saved to a temporary location (D:\TeamCity\BuildAgent1\temp\buildTmp):
[JetBrains dotCover] Coverage session finished [15/06/2014 12:22:14] [JetBrains dotCover] Coverage results post-processing started [15/06/2014 12:22:14] [JetBrains dotCover] Coverage results post-processing finished [15/06/2014 12:22:15] ##teamcity[importData id='mstest' file='D:\TeamCity\BuildAgent1\temp\buildTmp\tmp623A.tmp.teamcity.trx'] ##teamcity[importData type='dotNetCoverage' tool='dotcover' file='D:\TeamCity\BuildAgent1\temp\buildTmp\coverage_dotcover3838966080337633281.data'] Importing data from 'D:\TeamCity\BuildAgent1\temp\buildTmp\tmp623A.tmp.teamcity.trx' (21.94 KB) with 'mstest' processor MSTest report watcher [MSTest report watcher] Watching paths: [MSTest report watcher] D:\TeamCity\BuildAgent1\temp\buildTmp\tmp623A.tmp.teamcity.trx
I think this is the reason SonarQube shows no results available for unit test coverage.
In SonarQube, other data is shown, just the unit tests coverage results are missing.
Does anyone know if I can pass a parameter to dotCover so it saves the coverage report somewhere Sonar can find instead of a temporary location?
Unfortunately now it is impossible to configure it as you want. We have an issue http://youtrack.jetbrains.com/issue/TW-25204 to add a new parameter where will be stored a path to the coverage report in temp directory, please watch and vote.
Also there is a related issue http://youtrack.jetbrains.com/issue/TW-36940 to add ability to publish coverage data as artifacts.
so... how do I get C# code coverage data from TeamCity to Sonar?
All artifacts are saved to <TeamCity data directory>/system/artifacts folder, coverage artifacts are hidden and are placed under the .teamcity directory in the root of the build artifacts. So it is possible to get them from server in another build configuration (using artifact dependency). But as far as SonarQube also uses sources and binary files it should be executed at the same build configuration as dotCover (to avoid data inconsistency). Now we have no workaround for this issue.
I'm trying to avoid the complexity of throwing another build configuration into the mix.
I can see that the build generates a temporary file: coverage_dotcover38932812100056445441.data
Is it possible to run dotCover commandline to produce html coverage report from this file?
There's another issue, we're using TeamCity 8.0.4, which is bundled with dotCover 2.2
The C# plugin requires dotCover 2.7 (very weird, this version is too advanced and not yet bundled with TeamCity)
I executed the dotCover commandline to generate a coverage report manually.
So far I wan't able to get SonarQube to load a dotCover report.
I get an error from Sonar:
java.lang.IllegalArgumentException: Only dotCover HTML reports which start with "<!DOCTYPE html>" are supported.
The dotCover report starts with the HTML tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
It looks like dotCover and the new C# Sonar plugin are not friends...
The C# Sonar plugin associated with Sonar 4.3 and DotCover 2.7 do work together...
The Java error that you see is because you used the wrong DotCover command to generate the coverage report.
The Sonar plugin requires the output from an Analyse command or a Report command. You must specify that you want an HTML report.
When I run an Analyse command in DotCover 2.7 asking for an HTML report, the file produced starts like this:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
...and the C# Sonar plugin accepts it.
I do see another issue with coverage from DotCover, however. I am seeing DotCover 2.7 producing incomplete coverage reports which I then import into Sonar.
I have started a separate thread on this today (6th August 2014).
A SonarQube plugin has been released. Please try it, any feedback is highly appreciated.
You may be able to achieve what you want by adding a simple copy step after your tests / coverage run (I'm currently trying to solve exactly the same issue - will report back with my findings)
Can't guarantee it works at this stage, but worth a shot.
Thanks for your answer - I think you're correct, this is the way to go.
NCover costs money. My manager won't be so happy if I allocate budget to purchase licenses.
The SonarQube C# plugin documentation outlines dotCover, NCover, and OpenCover.
Looking at OpenCover, I found this plugin to TeamCity:
In order to try OpenCover, I have to go through the process of getting it approved by the company.
(all sort of security related, copyright infringement, and budgetary forms to fill up)
I guess I'll try to solicit some NCover licenses from other departments that use it.