Code coverage report for TSQLT on SonarQube not showing up

Hello All,

SQ Version : 7.9.1.27448
I am trying to run the TSQLT tests on database and publish the code coverage report to SonarQube

These are the steps I am following,

  1. Compile the sql project
  2. Deploy the dacpac on database
  3. Run TSQLT tests using SQLCover
  4. Exporting the results in Coverage.opencoverxml file
  5. Convert Coverage.opencoverxml to SonarQube format using ReportGenerator
    <?xml version="1.0" encoding="utf-8"?>
    <coverage version=“1” /
    <file path="[ABC].[abc-cde-ghi-nknknknk]" /
    After conversion, I do see all the report getting compiled in html format (Looks good)
  6. Adding below property in SonarQubePrepare task,
    sonar.sql.tsql.sqlcover.report=\SonarQube.xml
    Also tried below but no luck,
    sonar.coverageReportPaths=
    \SonarQube.xml
  7. No code coverage information on SQ, still shows 0.0%

Can someone help me figure this out? What am I doing wrong?
Same setup works fine for normal C# unit tests but does not work for TSQLT.
Has anyone tried implementing code coverage for TSQLT? Is this even possible?

Thanks in Advance!

Hey there.

If you are using gretard/sonar-sql-plugin you are better off asking for help on their Github repository (aka if you’re using a Community Edition of SonarQube).

If you’re using Developer Edition or above (with SonarSource’s T-SQL analyzer), you will need to convert your reports to Generic Test Data before importing them (using the sonar.coverageReportPaths analysis parameter you’ve already found).

1 Like

Hi @Colin

We are using Developer edition.
I am following the same procedure for normal C# unit tests by converting DynamicCodeCoverage.coveragexml to SonarQube readable xml which seems to be working fine for code coverage.
But for TSQLT, when I am trying to convert Coverage.opencoverxml to SonarQube format using ReportGenerator, the T-Sql scanner/analyzer does not seems to be working correctly.

Do you know how can I convert the Coverage.opencoverxml to a generic file format so that SQ can read and reflect the matrix on dashboard?
When I checked the analysis log I see lot of these warnings,
WARN: Unable to parse file ‘***.sql’ : Parse error at line 4 column 9:
Not sure if its relevant.

Support for a coverage tool varies by analyzer – the coverage formats supported for C# are different than those for TSQL.

A quick search led me to some tools on GitHub, like GitHub - jmecosta/OpenCover2SonarConverter: Converts OpenCover to SonarQube format

Take note of this section in our documentation on analyzing T-SQL

Important Note

With the default configuration, only files with the .tsql are analyzed as T-SQL, and files with the .sql file extension are analyzed as PL/SQL. This behavior is defined in Administration > General Settings > T-SQL > File Suffixes and Administration > General Settings > PL/SQL > File Suffixes . You can override these properties either at server level or at project level.

Hi Colin,

After last failed attempt to resolve this, we have started working this again.

Here are the steps we are performing,

  1. Compile the database solution
  2. Deploy a TSQLT dacpac on to database
  3. Ran below ps1 to run the tsqlt tests and generate the reports,
$baseDir = "C:\Users\xxx\SQLCover-0.5.0\src\SQLCover\releases\template"
$database = "TestDBName"
$server = "."
$coverageOutputDir = "C:\Users\xxx\SQLCover-0.5.0\src\SQLCover\releases\results" 
. "$baseDir\SQLCover.ps1" 
$results = Get-CoverTSql  "$baseDir\SQLCover.dll"  "server=$server;initial catalog=$database;integrated security=true;" "$database" "exec tSQLt.RunAll" 
New-Item -ItemType Directory -Force -Path $coverageOutputDir*
Export-OpenXml $results $coverageOutputDir
Export-Html $results  $coverageOutputDir

which gave Coverage.opencoverxml and Coverage.html

  1. Per your suggestion used the tool below to convert the Coverage.opencoverxml to sonarqube generic data
    GitHub - jmecosta/OpenCover2SonarConverter: Converts OpenCover to SonarQube format
  2. Passed this generic data file to SQ prepare task using sonar.coverageReportPaths.
    sonar.coverageReportPaths=$(Build.SourcesDirectory)\Databases\merged.cov.json

Still no signs of code coverage Metrix on sonarqube dashboard :frowning:

Can you please let me know what are we missing?

Thanks

@Colin Can you please help us out here? any pointers will be a great help.