惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 李国宝

2206年最佳边缘计算集群方案:Tailscale + k3s 谁不想要自己的Tailscale内网呢~ 腾讯云API网关废了?集群开源方案平替 来一打自建IP Proxy玩玩之Majora Github Copilot 比在座各位更会写代码。jpg .NET Core + React Antd Pro脚手架 【爬虫系列】2. 打开App逆向“潘多拉魔盒” Ratel:一直站在Android逆向巅峰的平头哥 【爬虫系列】1. 无事,Python验证码识别入门 【爬虫系列】0. 无内鬼,破解前端JS参数签名 利用容器逃逸实现远程登录k8s集群节点 边缘计算k8s集群SuperEdge初体验 能动手绝不多说:开源评论系统remark42上手指南 一次依赖注入不慎引发的一连串事故 反手来个K8S入门到跑路 MySQL Online DDL导致全局锁表案例分析 .NET Core教程--给API加一个服务端缓存啦 任务队列和异步接口的正确打开方式(.NET Core版本) .NET Core中使用RabbitMQ正确方式 - 李国宝 - 博客园
.NET Core单元测试之搞死开发的覆盖率统计(coverlet + ReportGenerator )
李国宝 · 2018-12-30 · via 博客园 - 李国宝

.NET Core单元测试之搞死开发的覆盖率统计

这两天在给项目补单元测试,dalao们要求要看一下测试覆盖率

翻了一波官方test命令覆盖率倒是有支持了,然而某个更新日志里面写着

【“Support for Linux and Mac will be considered separately in a subsequent effort.”】

吐血ing。。。

8102年都要过去了,微软同学你是不有点过分啊。

然后又翻了一堆资料之后发现,GitHub有dalao自己搞了个coverlet来支持测试覆盖率。

开源大法拯救世界啊!!!

star一个再说。

coverlet配置和使用

首先安装一下coverlet.


dotnet tool install --global coverlet.console

或者和我一样懒的话,直接在项目里面引用 "coverlet.msbuild" 这个包也行.

    <PackageReference Include="coverlet.msbuild" Version="2.5.0" />

引用之后,执行dotnet test 的时候加多三个参数

dotnet test /p:CollectCoverage=true /p:CoverletOutput='./results/' /p:CoverletOutputFormat=opencover
  • CollectCoverage 收集覆盖率

  • CoverletOutput 测试报告数据输出路径

  • CoverletOutputFormat 测试报告格式,支持这些格式json (default)/lcov/opencover/cobertura/teamcity

其他参数自己看一下文档说明就好.

执行之后大概会看到这些信息.

测试报告

PS:可怜的个位数覆盖率....

这个时候Test项目里面的results 文件夹里面就有一个coverage.opencover.xml 文件了.

打开这个文件大概长这个样.

xml

大概率这不是人看的东西.

然后另一个工具又出来了.

ReportGenerator

https://github.com/danielpalme/ReportGenerator

  • ReportGenerator converts XML reports generated by OpenCover, PartCover, dotCover, Visual Studio, NCover, Cobertura or JaCoCo into human readable reports in various formats.

这个工具可以讲上面这些不是人看的XML转换成HTML输出.

美滋滋啊美滋滋啊.

他们居然还有一个配置指导的页面ReportGenerator/usage

真良心!!!

我这边简单起见,直接安装 dotnet tool 全局工具算了.

dotnet tool install --global dotnet-reportgenerator-globaltool

安装好了之后,直接在命令行里面使用 reportgenerator 生成对应的测试报告即可.我这边的命令大概是:

reportgenerator '-reports:UnitTests/results/*.xml' '-targetdir:UnitTests/results'

打开UnitTests/results 下面的index.htm就能看到对应的测试报告了.

1

全文完.

明年见!