What are we doing?
Implementing code coverage for Microsoft SQL Server Database Project
How we are doing?
- “SQL Server Database” Project which contains stored procedure inside “Transact-SQL” script file
- “MSTest Unit Test” project which contains unit tests for Sql files ( Overview -Test cases to execute the stored procedure by passing its parameter values)
- Upload the results to the SonarCloud server using azure devops classic build pipeline as follows
- “Prepare analysis on sonarcloud ” task with standalone scanner to run the analysis
- “Visual Sudio Test” task to generate trx(test result) file and coverage file
- Convert Coverage File into CoverageXML using CodeCoverage.exe
- “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?