How to get C++ Code Coverage (GTest/vstest.exe) in Mixed C++/C#-Solution?

Environment:

  • TFS Server 16
  • SonarQube Enterprise Edition 8.9.7
  • C# Code Quality and Security 8.22.0.31243 (csharp)
  • CFamily Code Quality and Security 6.20.3.42796 (cpp)

I’m curently trying to setup SonarQube for a mixed C++/C#-Solution. So far, the code analysis works well, except the code coverage for the C++ part.

The current build pipeline looks like follows:

  • Run “Prepare Analysis Configuration”
  • Build the solution using MSBuild
  • Run the unit tests (vstest.exe /EnableCodeCoverage + GoogleTestAdapter and NUnitTestAdapter)
  • Download and Run the BuildWrapper
  • Run Code Analysis

The resulting (merged) .coverage file and the converted .coveragxml file look fine so far. They seem to contain the coverage results for both, the C# and the C++ modules.
For the C# part, everything is fine, the coverage is shown up in SonarQube without touching anything else.
However for the C++ part, I don’t get code coverage in SonarQube. I tried to set “sonar.cfamily.vscoveragexml.reportsPath=**/*.coveragexml” as well as leaving it unspecified, without having any success.

Any idea what I am missing?

Thanks a lot in advance!

Hey there.

You’re probably running up against some conflicting information about what reports are accepted.

In the UI we describe the following for sonar.cfamily.vscoveragexml.reportsPath:

Pattern for search for Visual Studio Coverage XML reports. The pattern may be either absolute or relative to the project base directory. For example: “**/.coveragexml" will find all ".coveragexml” files in all sub-directories of current project.

And in the docs we say .coveragexml files are forbidden.

C/C++/Objective-C

Analysis parameter Description
sonar.cfamily.vscoveragexml.reportsPath Path may be absolute or relative to the solution directory. Path wildcards (see above) are supported. Note that the .coveragexml report format offered by Visual Studio is not supported.

This description makes my head spin as much as it probably does others.

You’ll need to take .coverage files and convert them using CodeCoverage.exe. See this guide here:

We need to make things more clear… somewhere. I’ll ping internally. Hopefully this gets you closer.