登录
首页 >  Golang >  Go问答

如何自定义gocov命令以替代go工具?

来源:stackoverflow

时间:2024-03-16 09:09:24 319浏览 收藏

Go 1.10 版本及以上不再需要使用 `gocov` 命令来进行覆盖率测试,可以使用 `go test` 命令及其 `-coverprofile` 和 `-coverpkg` 选项来实现。通过指定 `-coverprofile` 选项,可以生成覆盖率配置文件,再使用 `go tool cover` 命令生成 HTML 报告或其他格式的报告。

问题内容

我有以下命令:

${GOPATH}/bin/gocov test ./... 2>test | ${GOPATH}/bin/gocov report

如果我使用 go 工具 cover,该命令会是什么样子?


解决方案


自go 1.10 go工具覆盖支持递归包绕过

go test ./... -coverprofile=coverage.out

这对我有用https://forum.golangbridge.org/t/how-to-do-go-test-coverage-for-system-testing/6479/3

go test -coverprofile=cover.out -coverpkg=server \
    && go tool cover -html=cover.out

理论要掌握,实操不能落!以上关于《如何自定义gocov命令以替代go工具?》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>