繁体   English   中英

Golang coverprofile 输出格式

[英]Golang coverprofile output format

我试图理解go test中的-coverprofile cover.out选项,特别是文件的格式。

例如,覆盖server.gocover.out产生输出:

mode: set
github.com/cnuss/api_server/server.go:47.2,48.16 2 0
github.com/cnuss/api_server/server.go:52.2,53.16 2 0
github.com/cnuss/api_server/server.go:57.2,58.16 2 0
github.com/cnuss/api_server/server.go:62.2,63.16 2 0
github.com/cnuss/api_server/server.go:67.2,68.16 2 0
github.com/cnuss/api_server/server.go:72.2,73.16 2 0
github.com/cnuss/api_server/server.go:77.2,78.16 2 0
  1. 每个不同的列是什么意思?
  2. 输出格式是否为“标准”格式,例如 gcov、xunit 等并可转换为另一种格式?

这些字段是:

name.go:line.column,line.column numberOfStatements count

来源

golang-nuts 社区 ( https://groups.google.com/forum/#!forum/golang-nuts ) 提供了一些有用的工具,可以将 Go 覆盖范围转换为更有用的格式。

JUnit 格式(用于总结测试执行):

# Prerequisites
go get github.com/jstemmer/go-junit-report
# Tests
go test -v | go-junit-report > report.xml

Cobertura 格式(用于详细说明代码覆盖率):

# Prerequisites
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
# Coverage
go test -coverprofile=cover.out
gocov convert cover.out | gocov-xml > coverage.xml

将我指向这个方向的线程在这里:https ://groups.google.com/forum/#!topic/golang-nuts/iUc68Zrxk_c

您可以使用 go cover工具处理封面配置文件:

打开显示带注释的源代码的 Web 浏览器:

    go tool cover -html=c.out

写出一个 HTML 文件而不是启动 Web 浏览器:

    go tool cover -html=c.out -o coverage.html

显示每个函数对标准输出的覆盖百分比:

    go tool cover -func=c.out

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM