Run tSQLt Unit Tests
With this build task, besides running tSQLt Unit Tests on a SQL Database, you'll also be able to:
Originally, there is no build task that does all those 3 tasks. Thinking from an automation and engineering perspective, once you run your unit tests, it would be good to have its results published somewhere to inspect and adapt your tests.
This task relies on 3 components:
This is an Open Source component written by Ed Elliot to extract code coverage from a tSQLt test execution.
OpenCover to Cobertura Converter
An Open Source tool written by Daniel Palme to convert OpenCover code coverage reports to Cobertura, a coverage report supported by Azure DevOps. See more here.
Daniel Palme also wrote a tool to convert XML Code Coverage reports into human readable reports in various formats.
Basically, this extension performs the following tasks, in order:
This extension is still in preview to gather information on using, feedback and tracking initial issues.
How to use it
If you just want your test (with or without Code Coverage) and you will not customize anything right now, just follow these steps:
Add the Run tSQLt Unit Tests build task to your pipeline
The only important thing here is to highlight that the working directory for the task will be the build sources directory. You can change this but it's recommended to keep it as it is.
Here, two required information:
You'll have default information filled here that is supposed to make it work by default with the requirements of the Publish Test Results task. You can also customize it.
By default, Code Coverage is disabled. If you want the task to also generate Cobertura code coverage reports, you must enable it. Remember that all those paths are relative to working directory\root folder
If any of your tests fail, the task will also fail. Because of that, you must mark the Continue on error option so your pipeline will publish test results and code coverage reports, if enabled.
Add the Publish Test Results to the pipeline
To have the test results available on the pipeline summary, you must publish it. To do that, you just need to use the Publish Test Results task:
Configure important parameters
Add the Publish Code Coverage Results task (if Code Coverage Enabled)
If you enabled Code Coverage on the Tests task, you'll need to publish its results to the pipeline summary.