请注意,Go 1.2 (Q4 2013, rc1 is available)现在将显示test coverage results:
go testgo tool covercover
$ go get golang.org/x/tools/cmd/cover
go test-cover
$ go test -coverprofile fmt ok fmt 0.060s coverage: 91.4% of statements $
go tool cover
Frank Shearar mentions:
The latest versions of Go (2013/09/19) use:
go test -coverprofile <filename> <package name>
Details on how to generate and analyze coverage statistics can be found by running the commands
$ go help testflag $ go tool cover -helpIvan Black提及in the comments:
go test -coverprofile cover.outgo tool cover -html=cover.out -o cover.htmlcover.html
我甚至不想等待浏览器打开,所以我定义了这个别名:
alias gc=grep -v -e " 1$" coverage.out我只输入
gc
,并列出了尚未涵盖的所有行(此处:coverage.out
行不以“1
”结尾)。