Golang 官方只提供了go test
单测覆盖率收集工具,无法像其他语言一样收集运行时二进制的覆盖率。
七牛曾在MTSC2018开源过一个实现方案,但这种方案有先天缺陷:1. 受限于go test
命令,程序必须关闭才能收集覆盖率,2. 会污染被测代码库,给本地开发带来不便,3. 会注入 flag 。
为此,七牛又研发了新的系统测试覆盖率收集工具:https://github.com/qiniu/goc
首先通过goc server
命令部署一个服务注册中心,它将会作为枢纽服务跟所有的被测服务通信。
使用goc build --center="<server>"
命令编译被测程序。goc 不会破坏被测程序的启动方式,所以你可以直接将编译出的二进制发布到集成测试环境。
环境部署好之后,就可以做执行任意的系统测试。而在测试期间,可以在任何时间,通过goc profile --center="<server>"
拿到当前被测集群的覆盖率结果。
也可以直接合并步骤 1 和 2 为:
goc run
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.
目前项目还处于初级阶段,所以现在:
欢迎来https://github.com/qiniu/goc提交 issue,贡献代码,一起完善 Golang 的系统测试覆盖率收集工具。
1
qq1340691923 2020-07-01 13:30:36 +08:00
挺一下!
|