go - gocov不会将完整的测试覆盖率结果上传到codeclimate中

标签 go test-coverage code-climate

基于StackOverflow上的question,我将测试覆盖率添加到了Gitlab CI / CD YAML文件中,并且我希望结果可以上传到代码环境中。

- go get github.com/axw/gocov/gocov
- export CC_TEST_REPORTER_ID=My_REPO_ID
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- gocov test -v ./... -coverprofile=out
- ./cc-test-reporter format-coverage --input-type gocov out
- ./cc-test-reporter upload-coverage
该脚本在我所有的程序包中都成功运行了测试,并且CI / CD的输出显示运行了不同程序包中的所有测试,但是将报告上载到codeclimate中仅显示只有一个文件具有test-coverage,这是最后一个测试程序包,而不是全部显示。
code-climate result report page

最佳答案

我在同一个stackoverflow链接中将解决方案与另一个答案混合在一起,最后创建了一个bash文件,并从我的yaml文件中像这样运行它,因此报告输出包含所有程序包报告,这是我的脚本:

go get github.com/axw/gocov/gocov
export CC_TEST_REPORTER_ID=My_ID
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build

for pkg in $(go list ./... | grep -v vendor); do
    go test -coverprofile=$(echo $pkg | tr / -).cover $pkg
done
echo "mode: set" > c.out
grep -h -v "^mode:" ./*.cover >> c.out
rm -f *.cover

./cc-test-reporter after-build

关于go - gocov不会将完整的测试覆盖率结果上传到codeclimate中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63570559/

相关文章:

go - 全局错误变量在初始化后保持为 nil

go - 如何使用 Go Gin 高效调用 localhost Handler?以及如何获取正在运行的url?

go - 如何从 Go 中的结构中的接口(interface)实例获取属性

flutter - 如何在 Flutter 应用程序中获取主要功能的代码覆盖率?

reactjs - 无法在 Windows 10 中使用 react 测试库生成 react 测试覆盖率

javascript - Travis CI 找不到 Karma 生成的 lcov.info 文件

go - 无法读取 UDP 回复(golang)

python - 具有条件导入和可选要求的 pytest 覆盖范围

node.js - Jest JS 测试覆盖率数据未从 Codeship 发布到 Code Climate

go - Golang 的 Codeclimate 测试覆盖格式化程序