V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
lyyyuna
V2EX  ›  Go 编程语言

开源一种新的 Golang 覆盖率收集方式

  •  1
     
  •   lyyyuna · 2020-07-01 11:56:34 +08:00 · 2392 次点击
    这是一个创建于 1393 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Golang 官方只提供了go test单测覆盖率收集工具,无法像其他语言一样收集运行时二进制的覆盖率。

    七牛曾在MTSC2018开源过一个实现方案,但这种方案有先天缺陷:1. 受限于go test命令,程序必须关闭才能收集覆盖率,2. 会污染被测代码库,给本地开发带来不便,3. 会注入 flag 。

    为此,七牛又研发了新的系统测试覆盖率收集工具:https://github.com/qiniu/goc

    效果图

    使用步骤

    1. 首先通过goc server命令部署一个服务注册中心,它将会作为枢纽服务跟所有的被测服务通信。

    2. 使用goc build --center="<server>" 命令编译被测程序。goc 不会破坏被测程序的启动方式,所以你可以直接将编译出的二进制发布到集成测试环境。

    3. 环境部署好之后,就可以做执行任意的系统测试。而在测试期间,可以在任何时间,通过goc profile --center="<server>"拿到当前被测集群的覆盖率结果。

    也可以直接合并步骤 1 和 2 为:

    1. goc run

    limit

    goc 在设计上希望完全兼容 go 命令行工具核心命令(go buld/install/run)。使用体验上,也希望向 go 命令行工具靠拢:

    goc help                                                                                                       [11:38:04][11492]
    goc is a comprehensive coverage testing tool for go language.
    
    Find more information at:
     https://github.com/qiniu/goc
    
    Usage:
      goc [command]
    
    Available Commands:
      build       Do cover for all go files and execute go build command
      clear       Clear code coverage counters of all the registered services
      diff        Do coverage profile diff analysis, it can also work with prow and post comments to github pull request if needed
      help        Help about any command
      init        Clear the register information in order to start a new round of tests
      install     Do cover for all go files and execute go install command
      list        Lists all the registered services
      profile     Get coverage profile from service registry center
      register    Register a service into service center
      run         Run covers and runs the named main Go package
      server      Start a service registry center
    
    Flags:
          --debug   run goc in debug mode
      -h, --help    help for goc
    
    Use "goc [command] --help" for more information about a command.
    

    目前项目还处于初级阶段,所以现在:

    1. 不支持 Windows
    2. go buld/install/run 包名规则支持不完善
    3. 等等

    欢迎来https://github.com/qiniu/goc提交 issue,贡献代码,一起完善 Golang 的系统测试覆盖率收集工具。

    1 条回复    2020-07-01 13:30:36 +08:00
    qq1340691923
        1
    qq1340691923  
       2020-07-01 13:30:36 +08:00
    挺一下!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5207 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:27 · PVG 17:27 · LAX 02:27 · JFK 05:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.