douni1396
douni1396
2018-06-27 07:45

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

  • sonarqube
已采纳

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 dsimib1625 3年前

    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.

    点赞 评论 复制链接分享

为你推荐