$ go test ./ -cover
ok mytest (cached) coverage: 42.9% of statements
go test 增加 -cover 参数可以查看测试用例的覆盖率
$ go test -coverprofile=size_coverage.out
PASS
coverage: 42.9% of statements
ok mytest 0.989s
也可以将覆盖结果存成一个文件,方便分析读取,比如用html来展示覆盖情况
go tool cover -html=size_coverage.out
此时浏览器将弹出窗口, 已覆盖 (绿色), 未覆盖(红色) 和 未埋点(灰色)
文章介绍了如何在gotest中使用-cover参数查看测试代码覆盖率,并提到可以将结果保存为文件(size_coverage.out),以便进一步通过gotoolcover-html生成HTML报告以直观展示代码覆盖率情况。
3297

被折叠的 条评论
为什么被折叠?



