douni1396 2018-06-27 07:45
浏览 265
已采纳

GoSonar:如何生成go test -json> report.json

How to generate go test -json > report.json

Golang Version: Go1.10.3

SonarQube Properties: sonar.go.tests.reportPaths = report.json

Offical Sonar Document -> https://docs.sonarqube.org/display/PLUG/Unit+Tests+Results+Import

Makefile

.PHONY: test
test:
    @$(foreach package,$(packages), \
        go test -coverprofile $(package)/cover.out -covermode=count $(package);)

.PHONY: cover
cover-xml:
    @$(foreach package,$(packages), \
        gocov convert $(package)/cover.out | gocov-xml > $(package)/coverage.xml;)
  • 写回答

1条回答 默认 最新

  • dsimib1625 2018-06-27 10:09
    关注

    In the Makefile, you generate the coverage report using:

    go test -coverprofile $(package)/cover.out $(package)

    To generate the test report you need to add:

    go test -coverprofile $(package)/cover.out -json $(package) > $(package)/test-report.json

    Or if you prefer a single report, you can create an empty file:

    echo -n > test-report.json

    And append all the tests to it:

    go test -coverprofile $(package)/cover.out -json $(package) >> test-report.json

    Note: I removed -covermode=count because it's not useful if the report is only used by SonarGo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥30 python安卓开发
  • ¥15 使用R语言GD包一直不出结果