开源一种新的 Golang 覆盖率收集方式 - V2EX
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 3028 次点击
    这是一个创建于 1935 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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     Solana     881 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 20:22 PVG 04:22 LAX 13:22 JFK 16:22
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86