Search code examples
sonarqubecode-coverage

How to treat uncovered files as having 0 coverage with SonarQube generic coverage XML?


Hello I'm using a custom plugin for an unsupported language and I'd like to show coverage information.

I've imported coverage generated in the XML format using the property sonar.coverageReportPaths

My coverage information is only for a few of the files in the project as there aren't unit tests for everything yet.

I was expecting that I would see coverage percentage expressed as a percentage of the total lines of code vs. covered lines in my supplied coverage. So if there are ten files with ten lines of code each and I provide coverage information for one file with 100% coverage then I would expect overall coverage to be shown as 10% (10/100).

Instead it shows 100% (10/10), i.e. only files with coverage information are considered as part of the total. I was assuming that coverage would be computed as covered lines as a percentage of the total lines of code in the project, at least that is how I understand it.

I found a property in the C++ plugin called sonar.cxx.coverage.forceZeroCoverage which seems to be intended for something like this, i.e. to assume that source files without coverage information are considered to have 0 coverage which would be useful.

Is there anything similar that I can use for generic coverage or do I have to figure out a way to generate coverage XML showing that every other line in the application is uncovered?


Solution

  • The plugin for the language needs to implement Executable Lines. That identifies which lines should be covered. The platform will take it from there with the math.

    Here are the guidelines SonarSource uses internally when deciding which lines to identify as coverable: https://docs.sonarqube.org/display/DEV/Executable+Lines