doupai5450 2015-07-14 17:20
浏览 355
已采纳

Golang CoverProfile输出格式

Thanks in advance for the help...

I'm trying to make sense of the -coverprofile cover.out option in go test, specifically the format of the file.

Covering server.go for example, yields the output in cover.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. What do each of the different columns mean?
  2. Is the format of the output in a "standard" format, e.g. gcov, xunit, etc. and convertable to another format?

Thanks again!!

  • 写回答

3条回答 默认 最新

  • doutuo2829 2015-07-15 20:47
    关注

    The golang-nuts community (https://groups.google.com/forum/#!forum/golang-nuts) provided a couple useful tools for converting Go coverage into more useful formats.

    JUnit Format (for summarizing test executions):

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

    Cobertura Format (for detailing code coverage):

    # 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
    

    The thread that pointed me in this direction was here: https://groups.google.com/forum/#!topic/golang-nuts/iUc68Zrxk_c

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码