{"id":15002859,"url":"https://github.com/sayantandey/sqlservercoverage","last_synced_at":"2025-10-30T09:31:02.710Z","repository":{"id":147210570,"uuid":"613129537","full_name":"sayantandey/SQLServerCoverage","owner":"sayantandey","description":"MS SQL Server code coverage for Stored Procedures (Branch + Statement)","archived":false,"fork":false,"pushed_at":"2024-11-06T17:24:06.000Z","size":109084,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-02T07:51:13.072Z","etag":null,"topics":["coverage","mssql-server","mssqlserver","reporting","sqlserver","stored-procedures","testing"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sayantandey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-13T00:11:21.000Z","updated_at":"2024-12-28T14:04:45.000Z","dependencies_parsed_at":"2023-05-28T01:45:35.583Z","dependency_job_id":null,"html_url":"https://github.com/sayantandey/SQLServerCoverage","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":0.24,"last_synced_commit":"aea57e3abd65d313187ae8b8993072030d386841"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayantandey%2FSQLServerCoverage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayantandey%2FSQLServerCoverage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayantandey%2FSQLServerCoverage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayantandey%2FSQLServerCoverage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sayantandey","download_url":"https://codeload.github.com/sayantandey/SQLServerCoverage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238950485,"owners_count":19557533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coverage","mssql-server","mssqlserver","reporting","sqlserver","stored-procedures","testing"],"created_at":"2024-09-24T18:53:18.379Z","updated_at":"2025-10-30T09:31:02.257Z","avatar_url":"https://github.com/sayantandey.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQLServerCoverage \n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/sayantandey/SQLServerCoverage/blob/main/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/sayantandey/SQLServerCoverage.svg)](https://github.com/sayantandey/SQLServerCoverage/releases/latest)\n[![.NET Core Desktop](https://github.com/sayantandey/SQLServerCoverage/actions/workflows/dotnet-desktop.yml/badge.svg)](https://github.com/sayantandey/SQLServerCoverage/actions/workflows/dotnet-desktop.yml)\n[![Github All Releases](https://img.shields.io/github/downloads/sayantandey/SQLServerCoverage/total.svg)]()\n\n##### Code coverage for SQL Server T-SQL \n\n##### Extended From [SQLCover](https://github.com/GoEddie/SQLCover).\n\n\u003e This project is based on [SQLCover](https://github.com/GoEddie/SQLCover) with additional features, bug fix and maintenances planned ahead.\n\n**SQLServerCoverage** is a tool for checking code coverage (both line and branch) of tests executed in SQL sever 2008 and above.\n\n![](./example/Report%20Summary.PNG)\n\n## Functionalities/Fixes added:\n\n:white_check_mark: Generate HTML Report Directly \n\n:white_check_mark: Branch Coverage\n\n:white_check_mark: CLI tools for different platforms \n\n:white_check_mark: Detailed documentation for setup\n\n:white_check_mark: Output SQL Server Generated Messages during Execution\n\n:white_check_mark: Generate latest Cobertura Report using 0.4 DTD\n\n:white_check_mark: Custom HTML Report (Without 3rd party dependency)\n\n:white_check_mark: Upgraded to `.NET 8.0`\n\n____\n\n# Index\n\n - [Download](#download)\n - [Build](#build)\n - [Installation](#installation)\n - [Usage](#usage)\n   - [1. CLI](#1-cli)\n   - [2. Cover tSQLt Scripts](#2-cover-tsqlt-script)\n   - [3. Check Coverage Asynchronously ](#3-check-coverage-asynchronously )\n - [Tidying up](#tidying-up)\n\n## Download\n\nDownload the [latest release](https://github.com/sayantandey/SQLServerCoverage/releases/latest) from the released packages. \n\n**Note:** If you are unable to find a release compatible for your system, consider building it from the codebase using `dotnet` tool . \n\nRead the [build](#build ) section for building the tool.\n\n## Build \n\n##### Follow these steps to build the tool for your environment \n\n* From the project root directory\n\n  ```\n  dotnet publish src/SQLServerCoverageCore/SQLServerCoverageCore.csproj  -c Release  -r win-x64 -o \"releases/\u003cRUNTIME_IDENTIFIER\u003e\" --self-contained true  -p:PublishSingleFile=true\n  ```\n\n  \u003e For `RUNTIME_IDENTIFIER` put the os version for your system. \n  \u003e\n  \u003e [Check this source to choose a runtime](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog) \n\n* Once finished, fetch the binary from `/releases/\u003cRUNTIME_IDENTIFIER\u003e` directory.\n\n\n## Installation\n1. Put the tool in a directory of your preference.\n2. Use the path to that directory as your environment variable \n\n___\n\n## Usage\n\n### 1. CLI\n\n```bash\nSQLServerCoverageCore --help\nCopyright (C) 2024 SQLServerCoverageCore\n\n  -v, --verbose             Set output to verbose messages.\n\n  -c, --command             Required. Choose command to run: Currently only Get-CoverTSql available\n\n  -e, --exportType          Required. Choose export options: Export-OpenXml, Export-BasicHtml, Export-DetailedHtml, Export-Cobertura\n  -e, --exportType          Required. Choose export options: Export-OpenXml, Export-Html, Export-ReportGeneratorHtml, Export-Cobertura\n\n  -b, --debug               Prints out detailed output.\n\n  -p, --requiredParams      Get required parameters for a command\n\n  -k, --connectionString    Connection String to the SQL server\n\n  -d, --databaseName        Default Database\n\n  -q, --query               Sql Query, Ex. tSQLt.runAll OR your custom test executor\n\n  -o, --outputPath          Output Path of The Export Result\n\n  -t, --timeout             Wait time in Seconds before terminating the attempt to execute test SQL command\n\n  -i, --ignore              Space separated list of database objects to ignore. Regex Accepted. Case sensitive depending on collationEx.\"sp_dummy_proc* sp_test_proc\"\n  -i, --ignore              Space separated list of database objects to ignore. Regex Accepted. Case sensitive depending on collation. Ex.\"sp_dummy_proc* sp_test_proc\"\n\n  --help                    Display this help screen.\n\n  --version                 Display version information.\n```\n\n### Example:\n\n\u003e #### Quick Check Using Docker \n\u003e\n\u003e 1. Go to the Docker directory and spin up the SQL Server in a docker container\n\u003e\n\u003e    ```\n\u003e    docker-compose -f \"./example/Docker/docker-compose.yaml\" up -d\n\u003e    ```\n\u003e\n\u003e 2. Then setup the mock test suite :\n\u003e    ```bash\n\u003e    SQLServerCoverage\u003edocker exec sql_coverage /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P StrONg_P/\\$ -i /scripts/mocked_test_suit.sql -C -N -t 30\n\u003e    Changed database context to 'sql_coverage_test'.\n\u003e    Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.\n\u003e    \n\u003e    (3 rows affected)\n\u003e    \n\u003e    ```\n\u003e\n\u003e 3. Runt the coverage server\n\u003e    ```\n\u003e    \"releases\\win-x64/SQLServerCoverageCore\" -v true -c Get-CoverTSql -e Export-Html -d \"sql_coverage_test\" -o \"example/Coverage Example/HTML Report\" -q \"EXEC coverage.sp_process_employee @firstName='John', @lastName='Test', @email='john.test@example.com', @birthDate='1990-01-01', @department='IT', @salary=60000.00, @operation='C'; EXEC coverage.sp_complex_business_logic @department='IT', @salaryAdjustment=5.0, @actionType='A';\" -k \"Server=localhost,1433;Database=sql_coverage_test;User Id=sa;Password=StrONg_P/\\$;TrustServerCertificate=True\" -t 30 -i \"exclude.sp_maintenance,exclude.sp_cleanup\"\n\u003e    ```\n\u003e\n\u003e    \n\n##### 1. OpenCover Format\n\nGenerate the coverage report as xml\n\n```bash\nSQLServerCoverageCore -v true -c Get-CoverTSql -e Export-OpenXml -d \u003cDATABASE_NAME\u003e -q \u003cQuery\u003e -o \u003cOUTPUT_PATH\u003e -k \u003cCONNECTION_STRING\u003e\n```\n\nThis will generate the OpenCover xml report in `OUTPUT_PATH` along with the source files in the database it is executed.\n\n##### 2. HTML Format\n\nGenerate the coverage report as html. It leverages ReportGenerator to Generate Inline HTML Report of Coverage.\n\n```bash\nSQLServerCoverageCore -v true -c Get-CoverTSql -e Export-Html -d \u003cDATABASE_NAME\u003e -q \u003cQuery\u003e -o \u003cOUTPUT_PATH\u003e -k \u003cCONNECTION_STRING\u003e\n```\n\n![](./example/Coverage%20Check%20CLI.gif)\n\n___\n\n### 2. Cover tSQLt Script\n\n\u003e [tSQLt](http://tsqlt.org/) is a unit testing framework for Microsoft SQL Server. \n\nIt can be used with tSQLt framework to check the coverage.\n\nIf you have a script you want to cover then you can call:\n```\nSQLServerCoverageCore -v true -c Get-CoverTSql -e Export-OpenXml -d \u003cDATABASE_NAME\u003e -q \"exec tSQLt.RunAll\" -o \u003cOUTPUT_PATH\u003e -k \u003cCONNECTION_STRING\u003e\n```\n\nThis will generate a openxml coverage report where you can either examine the amount of statement covered or use the report to generate HTML report using [ReportGenerator](https://github.com/danielpalme/ReportGenerator).\n\n___\n\n### 3. Check Coverage Asynchronously \n\n\u003e :construction: This will soon be made available to be used from CLI. Now DLL need to be used.\n\nIf you want to have more control over what is covered, you can start a coverage session, run whatever queries you like from whatever application and then stop the coverage trace and get the CoverageResults which you can then use to generate a report.\n\n```\n$coverage = new-object SQLServerCoverage.CodeCoverage($connectionString, $database)\n$coverage.Start()\n#Execute The SQL scripts\n$coverageResults = $coverage.Stop()\n```\n\n\n\n___\n\n ## Tidying up\n\n When we target local sql instances we delete the trace files but when targetting remote instances we are unable to delete the files as we do not (or potentially) do not have access. If this is the case keep an eye on the log directory and remove old \"SQLServerCoverage-Trace-*.xel\" and \"SQLServerCoverage-Trace-*.xem\" files. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayantandey%2Fsqlservercoverage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayantandey%2Fsqlservercoverage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayantandey%2Fsqlservercoverage/lists"}