# Code Coverage 0.0% for TSQL Projects(Contains Stored Procedures, Tables, Scripts etc)

**URL:** <https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938>\
**Category:** SonarQube Cloud\
**Tags:** tsql, coverage, scanner\
**Created:** [July 5, 2021, 4:56pm UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938 "2021-07-05T16:56:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![supravat.samanta](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/supravat.samanta/32/23602_2.png) [@supravat.samanta](https://community.sonarsource.com/u/supravat.samanta)\
**Post date:** [July 5, 2021, 4:56pm UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/1 "2021-07-05T16:56:15Z")

</div>

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.

Any suggestions/steps to coverage TSQL projects in Sonar Cloud will be appreciated.

---

<div class="post-metadata">

**Author:** ![supravat.samanta](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/supravat.samanta/32/23602_2.png) [@supravat.samanta](https://community.sonarsource.com/u/supravat.samanta)\
**Post date:** [July 6, 2021, 9:01am UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/2 "2021-07-06T09:01:31Z")

</div>

Any help you can give would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![supravat.samanta](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/supravat.samanta/32/23602_2.png) [@supravat.samanta](https://community.sonarsource.com/u/supravat.samanta)\
**Post date:** [July 6, 2021, 11:05am UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/3 "2021-07-06T11:05:26Z")

</div>

We have used MSTest as testing framework for writing all Stored Procedures unit test case for TSQL projects.  
Dynamic Code Coverage Tools \> CodeCoverage.exe : Should the sonar cloud will cover the code coverage for all Stored Procedures?

Its showing now 0.0% coverage for all Stored Procedures though all are having the valid Unit Test cases.

Is it a bug or something wrong we are doing as part of code coverage process.

---

<div class="post-metadata">

**Author:** ![supravat.samanta](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/supravat.samanta/32/23602_2.png) [@supravat.samanta](https://community.sonarsource.com/u/supravat.samanta)\
**Post date:** [July 6, 2021, 12:37pm UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/4 "2021-07-06T12:37:29Z")

</div>

Below steps followed as part of the code coverage Azure/Sonar configuration.

- Used task with standalone scanner to run the analysis
- Task to generate .trx (test result) file and coverage file
- Convert Coverage File into .coverageXML using CodeCoverage.exe tool
- Task to upload the .coverageXML results into the SonarCloud

---

<div class="post-metadata">

**Author:** ![janos](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/janos/32/60_2.png) [@janos](https://community.sonarsource.com/u/janos)\
**Post date:** [July 20, 2021, 8:16am UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/7 "2021-07-20T08:16:08Z")

</div>

> [@supravat.samanta](#):
>
> 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.

Can you please clarify what you mean by “cant read this coverage file”? Did an error message tell you this in the output of the scanner? Can you please copy paste the line with the message, and any relevant lines before it?

> [@supravat.samanta](#):
>
> Below steps followed as part of the code coverage Azure/Sonar configuration.
> 
> - […]
> - Task to upload the .coverageXML results into the SonarCloud

Can you please clarify how you did this last step?

Can you share the complete scanner command used? And any additional configuration related to running the scanner, for example in `sonar-project.properties` file.

---

<div class="post-metadata">

**Author:** ![Gangadhar](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/gangadhar/32/23716_2.png) [@Gangadhar](https://community.sonarsource.com/u/Gangadhar)\
**Post date:** [July 20, 2021, 12:05pm UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/10 "2021-07-20T12:05:10Z")

</div>

Hello @janos

Thanks for reaching us to provide quick guidance. We are doing the below process

Implementing code coverage for Microsoft SQL Server Database Project

How we are doing?

1. “SQL Server Database” Project which contains stored procedure inside “Transact-SQL” script file
2. “MSTest Unit Test” project which contains unit tests for Sql files ( Overview -Test cases to execute the stored procedure by passing its parameter values)
3. Upload the results to the SonarCloud server using azure devops classic build pipeline as follows
4. “Prepare analysis on sonarcloud ” task with standalone scanner to run the analysis
5. “Visual Sudio Test” task to generate trx(test result) file and coverage file
6. Convert Coverage File into CoverageXML using CodeCoverage.exe
7. “Run Code Analysis” task to upload the CoverageXML results to the SonarCloud server  
Sonar Cloud Code Coverage Report:

Expected: Expected 100% coverage to Transact-SQL script file as we written unit test case for stored procedure execution.

Actual : Showing 0.0% Coverage to Transact-SQL script file. We gone through the file and we noticed that with highlighted red color saying “Not covered by Tests” in every SQL (Ex: Select) statement and so on…

HELP NEEDED TO KNOW : Does sonar cloud code coverage of Transact-SQL script file cover as a whole or Individual statement inside the file?

---

<div class="post-metadata">

**Author:** ![janos](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/janos/32/60_2.png) [@janos](https://community.sonarsource.com/u/janos)\
**Post date:** [July 20, 2021, 12:51pm UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/11 "2021-07-20T12:51:21Z")

</div>

In order to see test coverage data on SonarCloud, the following is needed:

- Test coverage report files, in some format supported by SonarCloud.
- The scanner needs to find the report files to import them. Usually it can find the report files at typical locations, when in doubt, it’s best to specify the locations explicitly.

To answer the first requirement (report files in some supported format), I reviewed our documentation on [Test Coverage](https://sonarcloud.io/documentation/enriching/coverage/), which mentions nothing about SQL. Indeed our teams confirm that our TSQL plugin doesn’t have specific logic to directly import TSQL coverage reports such as the ones mentioned in this thread.

In such case, the alternative is to use [Generic Test Data](https://sonarcloud.io/documentation/enriching/generic-test/). This is a generic format that we support, explained on that doc page. That is, in order to see test coverage data for TSQL, you need to convert your reports from coveragexml format to this custom format, and tell the scanner the path to the generated report files using the `sonar.coverageReportPaths` parameter.

A quick search led me to this tool:

> **[jmecosta/OpenCover2SonarConverter](https://github.com/jmecosta/OpenCover2SonarConverter)**
>
> Converts OpenCover to SonarQube format. Contribute to jmecosta/OpenCover2SonarConverter development by creating an account on GitHub.

I’m not sure if this will work with your current report format, or if changing your report format to OpenCover is possible for you. I hope this may help you get started.

---

<div class="post-metadata">

**Author:** ![Gangadhar](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/gangadhar/32/23716_2.png) [@Gangadhar](https://community.sonarsource.com/u/Gangadhar)\
**Post date:** [July 20, 2021, 2:33pm UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/13 "2021-07-20T14:33:43Z")

</div>

Thanks @janos for your quick help. We will explore all the possible ways you mentioned and will comeback with our outcome soon.

---

<div class="post-metadata">

**Author:** ![Andrei\_Epure](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andrei_epure/32/77402_2.png) [@Andrei\_Epure](https://community.sonarsource.com/u/Andrei_Epure)\
**Post date:** [December 10, 2021, 1:44pm UTC](https://community.sonarsource.com/t/code-coverage-0-0-for-tsql-projects-contains-stored-procedures-tables-scripts-etc/45938/14 "2021-12-10T13:44:10Z")

</div>

Split this topic on December 10, 2021, 1:44pm UTC

A post was split to a new topic: [Import TSQL code coverage in SQ](https://community.sonarsource.com/t/import-tsql-code-coverage-in-sq/54692)
