Golang 增量覆盖率统计

2020-07-10  本文已影响0人  夏国栋

实践项目:趣头条-实惠喵后端(购物返利用 实惠喵app,省钱! )

单元/功能 测试增量覆盖率统计
1.通过测试工具获取到全量覆盖率统计信息,输出到c.out(使用方法见 Golang 全量覆盖率统计),拿单元测试举例:

go test -coverprofile=c.out

c.out内容格式如下:

image.png
2.使用工具gocovgocov-xml将覆盖率输出转换成xml格式的报告:

gocov convert c.out | gocov-xml > coverage.xml

gocov 安装/说明:https://github.com/axw/gocov/
gocov-xml 安装/说明:https://github.com/AlekSi/gocov-xml

3.使用工具diff-cover获取增量覆盖率:

diff-cover coverage.xml --compare-branch=HEAD^ --html-report report.html --fail-under=80

diff-cover 安装/说明:https://github.com/Bachmann1234/diff_cover


遇到的问题总结

No lines with coverage information in this diff.

经排查因为之前在将覆盖率统计信息转换成xml格式时,用的gocover-cobertura工具,该工具转换后的格式 diff-cover工具可能未做兼容,导致一直返回如上结果,按照如上步骤2解决了该问题

上一篇 下一篇

猜你喜欢

热点阅读