在Golang中创建一个详细的测试覆盖率报告和总体百分比

468 阅读1分钟

这个例子输出最终的测试覆盖率报告。它按每个文件中的功能分解了覆盖率。最后,报告输出整体测试覆盖率。

例子

覆盖所有文件。

go test -v -coverpkg=./... -coverprofile=coverage.log ./...

这不包括/internal/pkg/test 文件夹中的所有文件。

go test -v -coverpkg=./... -coverprofile=coverage.tmp ./...

对于第一行,最好是这样。看看标志的具体作用。

go test -v -race -bench -benchmem -timeout=120s -count=1 -cover -coverpkg=./... -coverprofile=coverage.tmp ./...

输出

github.com/Inanzzz/game/cmd/gouthenticator/main.go:15:		        main			0.0%