How to calculate code coverage in .NET and integrate into Azure DevOps
ฝัง
- เผยแพร่เมื่อ 27 พ.ค. 2024
- Support my channel on Patreon platform: / artemgrabovski
Hi! I’m Artem Grabovski and today we will discuss how you could efficiently use code coverage tools in .NET and integrate them into Azure DevOps.
In this video we will discuss the following questions:
- Which open source library you could use to calculate code coverage in .NET?
- How to visualize code coverage reports?
- How to integrate code coverage into YAML build pipelines in Azure DevOps?
- How to control advanced settings for code coverage tools?
0:00 Introduction to code coverage.
1:26 Demo. Integrate code coverage into project.
4:50 Demo. Visualize Coverlet report using Report Generator.
7:27 Demo. Integrate code coverage into YAML build pipelines in Azure DevOps.
Coverlet: github.com/coverlet-coverage/...
Report generator: github.com/danielpalme/Report...
My personal book recommendation about unit-tests: amzn.to/3LuqJTl
Plainzer, free dividend tracker app: plainzer.com
My setup for TH-cam videos:
- Microphone. Elgato Wave 3: amzn.to/3nitJc6
- Camera. Anker PowerConf C200: amzn.to/44fXqLz
Follow me:
- LinkedIn: / artemgrabovski
- Instagram: / artemgrabovski
#dotnet #csharp #codecoverage #coverlet #unittesting #azuredevops - วิทยาศาสตร์และเทคโนโลยี
❤
I got to know today by this videos.. test and code coverage are difference and relation. Thank 😮😊
Very interesting, explains it very well!
Thanks for your feedback!
Nicely done Artem! There is something you probably could consider for the next video: on real projects, there are many assemblies with the Unit Tests. The approach you demonstrated will just grab the firstly found cobertura report found while you'll have many of them, for each assembly. So, if you want it to work properly, I believe, you need to combine the reports prior to publishing the report results.
Thanks, Sergey! I really appreciate your feedback! You’ve mentioned problem which is actual for real projects. There are multiple ways how to resolve this one.
Solution 1. Resolve on ReportGenerator level (without integration into Azure DevOps)
ReportGenerator supports HTML report generation based on multiple cobertura files.
Additional information: github.com/danielpalme/ReportGenerator/issues/282
Solution 2. Resolve on Azure DevOps level (under the hood it’s using ReportGenerator)
New version of “Publish Code Coverage Results” build task supports multiple report files. At the same time, for some reasons this build task still depends on old .NET Core SDK.
Additional information: learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/publish-code-coverage-results-v2?view=azure-pipelines
I will take into consideration these problems in the next videos!
Good work.. Thank You
Thanks for this useful comment. I will try to apply it in my project
Good luck! If you have any additional questions, just let me know
Great! Thanks
Thanks!
Nice explanation!
Thank you!!!
Glad it was helpful!
thanks. Can you force failure in the pipeline if the the threashold is not achieved?
Very nice explanation
But I have one question, How can I create a dashboard for all pipelines? For example, if I have two repo and both have their own code coverage, but I want to create one dashboard that shows all the metrics that I have in both pipelines
Thanks a lot! Unfortunately Azure DevOps doesn't support dashboard with code coverage for all pipelines. At the same time you could use SonarQube for these purposes (www.sonarsource.com/products/sonarqube). It will provide you a page with list of services and information about code coverage for each of them.
Very nicely explained.
One question (may be a silly one).
It can be configured on any kind of unit tests, right (you used XUnit)? I mean it can be configured on NUnit and MSTests too?
It is not dependent on the unit testing framework, right?
You are totally correct, it doesn’t depend on some specific test framework