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

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 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备