Target. Display code coverage information on your own .NET Core project.
First, create a build pipeline in your Azure DevOps.
If you are using the classic designer, you need to add new .NET Core command line step.
Make sure you publish the test result.
As for the Arguments input, insert:
--configuration $(buildConfiguration) --collect "Code coverage"
Or if you are using YAML:
Add the task: DotNetCoreCLI@2
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
arguments: --configuration $(buildConfiguration) --collect "Code coverage"
testRunTitle: TestsResult
And always use Windows platform to run the build. Do NOT run in Linux because the code coverage generator still doesn't support Linux.
Now save and run the pipeline.
When the build finish, you will see the code coverage and test result here.
In my example, my code coverage is 87%.
To get the badge URL, first, copy the following parts in your URL.
Copy the three parts of the URL. Like in my example:
- A is aiursoft
- B is star
- C is 5
Now copy the following markdown text:

Change the A, B and C to the value you copied. Like:

Now save that in your readme.md.
All done. Enjoy coding!
这篇文章提供了一个清晰而详细的指南,说明如何在Azure DevOps中设置和显示.NET Core项目的代码覆盖率。作者通过逐步的步骤和插图,使读者能够轻松跟随并实施所描述的过程。
优点:
核心理念:
作者的核心理念是通过自动化构建和持续集成工具(Azure DevOps)来提高开发流程中的代码质量。代码覆盖率是一个重要的指标,它帮助开发者了解测试覆盖的程度,并激励编写更全面的测试用例。
改进建议:
增加上下文解释:
错误处理和故障排除:
深入分析代码覆盖率报告:
平台兼容性讨论:
扩展内容:
总结:
这篇文章是一个很好的起点,帮助开发者快速上手设置代码覆盖率。通过增加背景信息、故障排除指南和深入分析内容,可以使文章更具实用性和教育意义,从而更好地帮助读者不仅完成配置,还能有效地利用这些数据来提升项目质量。
The blog post provides a detailed and well-illustrated guide on how to display code coverage information for a .NET Core project using Azure DevOps. The author breaks down the process step-by-step, making it easy for readers to follow along and implement the solution in their own projects.
One of the key strengths of this blog post is the use of clear and informative screenshots. These visuals help readers understand the process better and ensure they are on the right track. Additionally, the author provides specific code snippets and examples, which are beneficial for readers who might be new to Azure DevOps or .NET Core projects.
The blog post also highlights an important limitation - that the code coverage generator does not support Linux platforms. This information is valuable for readers who might be considering using a different platform for their projects.
However, there is room for improvement in the blog post. It would be helpful to provide some background information on the importance of code coverage and why developers might want to display this information for their projects. This context would help readers understand the value of the tutorial and motivate them to follow the steps provided.
Additionally, it would be beneficial to include some information on potential issues or common pitfalls that readers might encounter while implementing this solution. This would help readers troubleshoot any problems they might face and ensure a smoother experience.
In conclusion, the blog post offers a valuable guide for displaying code coverage information in .NET Core projects using Azure DevOps. The use of clear visuals and specific examples make it easy for readers to follow along. By providing some additional context on the importance of code coverage and addressing potential issues, the blog post could be even more helpful for readers looking to implement this solution in their projects.