Testing SonarQube Coverage Using MsTest

I am trying to get SonarQube while working with a simple network dot application. I had some success when it started, but the code didn't work.

It seems that many other people faced this problem when SonarQube stopped supporting many "go to" coverage tools, such as DotCover and OpenCover via Gallio

The following are examples:

  • Runner sonar error while processing .coveragexml file created from MSTest Visual Studio

  • VS2013 CodeCoverage.exe script file never parses

I tried several VS command line tools to create 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 wrote some code to hide it in the .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 use the XSLT stylesheet in what the SonarQube runner can use

 <?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 start sonar

  • MSBuild.SonarQube.Runner.exe Get Started
  • Msbuild
  • MSBuild.SonarQube.Runner.exe end

I am getting errors like Caused By: unknown XML Node , Pending Coverage , but got Results

This is because its not like the structure of my XML, but I'm not sure what it expects and how much work I have to do in the coverage file in order to convert it to a format that Sonar likes

Hope I went the wrong way, and there is an easy way to integrate VS Coverage or coveragexml files into Sonar without much difficulty.

Additional information about my Sonar plugins

  • C # = 4.1
  • Total coverage = 1.1
+7
code-coverage mstest sonarqube vstest
source share
1 answer

Both OpenCover and dotCover reports are supported by the C # 4.1 plugin. Set the sonar.cs.dotcover.reportsPaths or sonar.cs.opencover.reportsPaths for both tools to import code coverage.

Gallio is not a very suitable tool: the project has been inactive since 2013. The main problem with the SonarQube C # Plugin 2.x plugin, which relied on Gallio, is that it launches Gallio on its own - a user to configure how tests should be run and collect coverage.

Now the situation is much simpler: launch your favorite code coverage tool, ask him to create a report and submit it to Runner SonarQube MSBuild.

If you are using Team Foundation Server 2013, enabling code coverage is the selection of the Enable Code Coverage option in the assembly definition.

Now it’s very sad and confusing that Microsoft has two different .coveragexml and that the SonarQube C # plugin supports only one of them (that is, at the moment see http://jira.sonarsource.com/browse/SONARNTEST-3 ).

In anticipation that this ticket will be fixed, follow these steps to create the expected .coveragexml report (note: replace 14 with 12 in different ways if you use VS 2013 instead of 2015):

  • MSBuild.SonarQube.Runner begin /k:SonarQube_Project_Key /n:SonarQube_Project_Name /v:1.0 /d:sonar.cs.vscoveragexml.reportsPaths=%CD%\VisualStudio.coveragexml
  • msbuild
  • "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output:VisualStudio.coverage "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "UnitTestProject1\bin\Debug\UnitTestProject1.dll"
  • "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:VisualStudio.coveragexml VisualStudio.coverage
  • MSBuild.SonarQube.Runner end

I would not recommend using XSLT to convert code coverage report formats, use the Microsoft CodeCoverage.exe tool CodeCoverage.exe .

+4
source share

All Articles