打印 Go Test 的代码覆盖
在 Go Package 种执行 cover,检测每行代码的测试情况
打印 Go Test 的代码覆盖
打印 Go Test 的代码覆盖
使用方法
将这段代码复制进 ~/.zshrc
或者是 ~/.bashrc
等文件中(取决于你的命令行),然后在任何一个 Go Package 中执行 cover
即可。
1
2
3
4
cover() {
t="/tmp/go-cover.$$.tmp"
go test -coverprofile=$t $@ && go tool cover -html=$t && unlink $t
}
参考资料
This post is licensed under CC BY 4.0 by the author.