Code Coverage Metrics for SQL Projects in SonarQube

SonarQube Version - Enterprise Edition Version 7.6 (build 21501)LGPL v3

We are trying to capture the Code Coverage metrics in SonarQube for SQL Projects but it doesn’t seem to be working.

We are able to scan the SQL Project repository and get metrics around Bugs, Code Smells, Duplications but not Code Coverage.

We are using tSQLt for writing Unit Tests for our SQL Projects. We have generated the Code Coverage file using SQLCover. However SonarQube cant read this coverage file and generate the code coverage metrics.

Is this a Sonarqube limitation?

There’s currently no easy way to import coverage data for T-SQL in SonarQube.

You have to provide an XML report which conforms to the “Generic coverage” schema supported by SonarQube: see the documentation. Your report should look like:

<coverage version="1">
  <file path="myprocedures/file1.sql">
    <lineToCover lineNumber="6" covered="true"/>
    <lineToCover lineNumber="7" covered="false"/>
  </file>
  <file path="myprocedures/file2.sql">
     ...
  </file>
</coverage>

I don’t know what kind of report you can get out of tSQLt or SQLCover. If it’s already in an XML format, maybe you can set up an XML transformation. However, it may be tricky to generate the correct file paths and line numbers.