作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
基于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,这是最后一个测试程序包,而不是全部显示。
最佳答案
我在同一个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/
我是一名优秀的程序员,十分优秀!