I have been trying to get SonarQube
working with a simple dot net app. I have had some success getting it up and running but code coverage is not working.
It looks like many other people have faced this issue when SonarQube discontinued support for many of the 'go to' coverage tool such as DotCover and OpenCover
via Gallio
Examples which I have followed are:
Sonar Runner errors out during processing of .coveragexml file produced from Visual Studio's MSTest
VS2013 CodeCoverage.exe runsettings file never parses
I have tried a few of the VS command line tools to generate a .coverage
file
vstest.console.exe .\UnitTestProject1\bin\Debug\UnitTestProject1.dll /EnableCodeCoverage
and
CodeCoverage.exe collect /output:DynamicCodeCoverage.coverage .\UnitTestProject1\bin\Debug\UnitTestProject1.dll
And written some code like to covert it into a .coveragexml
file from here
To get the following XML:
<?xml version="1.0" standalone="yes"?>
<CoverageDSPriv>
<Module>
<ModuleName>unittestproject1.dll</ModuleName>
<ImageSize>32768</ImageSize>
<ImageLinkTime>0</ImageLinkTime>
<LinesCovered>12</LinesCovered>
<LinesPartiallyCovered>0</LinesPartiallyCovered>
<LinesNotCovered>0</LinesNotCovered>
<BlocksCovered>9</BlocksCovered>
<BlocksNotCovered>0</BlocksNotCovered>
<NamespaceTable>
<BlocksCovered>9</BlocksCovered>
<BlocksNotCovered>0</BlocksNotCovered>
<LinesCovered>12</LinesCovered>
<LinesNotCovered>0</LinesNotCovered>
And even used XSLT stylesheet provide in one that could be used by the SonarQube runner
<?xml version="1.0" encoding="utf-8"?>
<results>
<modules>
<module name="unittestproject1.dll" path="unittestproject1.dll" block_coverage="100" line_coverage="100" blocks_covered="9" blocks_not_covered="0" lines_covered="12" lines_partially_covered="0" lines_not_covered="0">
<functions>
<function name="Setup" type_name="UnitTest1" block_coverage="100" line_coverage="100" blocks_covered="1" blocks_not_covered="0" lines_covered="2" lines_partially_covered="0" lines_not_covered="0">
<ranges>
<range source_id="1" covered="yes" start_line="13" start_column="9" end_line="13" end_column="10" />
<range source_id="1" covered="yes" start_line="15" start_column="9" end_line="15" end_column="10" />
</ranges>
</function>
when I run Sonar
- MSBuild.SonarQube.Runner.exe Begin
- MSBuild
- MSBuild.SonarQube.Runner.exe end
I get errors like Caused By:
unknown XML Node
, Expect Coverage but got Results
This is because its does not like the structure of my XML, but I am not sure what is is expecting and how much work I have to do on the coverage file to convert it into a format that Sonar likes
Hopefully I have been going down the wrong path and there is a simple way to integrate VS Coverage or coveragexml
files into Sonar without too much work
Extra Information on my
Sonar plugins
are
- c# = 4.1
- Generic Coverage = 1.1