golang查看go test代码覆盖率

307 阅读1分钟

执行 go test 命令,会自动统计覆盖率

[root@localhost sdpsc]# go test ./... -coverprofile=size_coverage.out

1684225864324.png

然后用go tools命令输出到html文件

go tool cover -html=size_coverage.out 

1684226024172.png