0

I am trying to display code coverage for my project in sonarqube. The closest I got so far is that it shows the coverage on header files, but not on source files.

My Setup: I have a project with multiple modules and want to get the coverage for a C++ library (as a CMake-project). The unit tests are implemented with googletest and the build pipeline is executed on a Jenkins server.

This is what I tried: I ran gcovr --keep or gcov *.o and put in the sonar-project.properties my-module.sonar.cfamily.gcov.reportsPath=path-to-gcov-files. (Unsurprisingly,) I got the same result for both. Sonarqube shows some code coverage, but only for header files. In the sonarqube logs I see Sensor gcov [cpp] and some lines about what it does.

I ran gcovr --sonarqube coverage.xml and put in the sonar-project.properties my-module.sonar.coverageReportPaths=./coverage.xml. This gives no coverage result in sonarqube and I can't find anything in the logs related to this. However, when I just run gcovr I get coverage result for both header files and source files, I just don't know how to transfer this to sonarqube.

Can anyone tell me what I am doing wrong?

tabs
  • 1
  • 1
  • I don't use sonarqube, but did you build your library with coverage flags? – Stephen Newell Aug 24 '22 at 14:12
  • I did. To be honest I don't fully understand this and tried different flags. I started out with ```set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")``` in my CMake file and later tried ```set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O0 -fprofile-arcs -ftest-coverage")```. I guess this is not the problem as I get a report when running gcovr locally? – tabs Aug 24 '22 at 14:38
  • If you can get the report when running locally, you probably setup the flags right. Somebody who understands sonarqube will have to take a look. – Stephen Newell Aug 24 '22 at 14:42

0 Answers0