- In your Visual Studio solution, add a unit test project (end of name with Tests).
- Reference the Nuget package coverlet.msbuild which will be used as an extension of the dotnet test command used later.
dotnet test --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=./TestResults/Coverage/
reportgenerator -reports:.\TestResults\Coverage\coverage.cobertura.xml -targetdir:.\CodeCoverage -reporttypes:HtmlInline_AzurePipelines
- In Azure DevOps Pipeline Build, add a task .NET Core to perform unit tests and collect data on code coverage (via coverlet). This task will generate a coverage.cobertura.xml file in your test project folder, in Cobertura format which is supported by Azure DevOps.
- Commande :
Test
- Path to projet(s) :
**/*[Tt]ests/*.csproj
- Arguments :
--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=./TestResults/Coverage/ /p:CoverletOutputFormat=cobertura
- Publish test results and code coverage : checked
- Commande :
- Via the Marketplace, add the extension[ReportGenerator] (https://marketplace.visualstudio.com/items?itemName=Palmmedia.reportgenerator) (from Palmmedia) and this task in your Pipeline:
- Reports :
**/coverage.cobertura.xml
- Target directory :
CoverageReport
- Report types:
HtmlInline_AzurePipelines;Cobertura
- Reports :
- Add a task Publish code coverage results to publish the HTML report in a Coverage tab of the Build Summary.
- Code coverage tool :
Cobertura
- Summary file :
**/coverage.cobertura.xml
- Report dyrectory :
CoverageReport
- Code coverage tool :
Exclude Any assembly:
reportgenerator -assemblyfilters:-BuildLibrary -reports:.\TestResults\Coverage\coverage.cobertura.xml -targetdir:.\CodeCoverage -reporttypes:HtmlInline_AzurePipelines
+ to include and - to exclude and Name of the assembly without extension.
File Filter:
reportgenerator -filefilters:-*Reference.cs* -reports:.\TestResults\Coverage\coverage.cobertura.xml -targetdir:.\CodeCoverage -reporttypes:HtmlInline_AzurePipelines
Ref: