How to measure code coverage in Golang?

前端 未结 11 2060
花落未央
花落未央 2020-12-22 16:12

Has anyone succeeded in generating code coverage for Go unit tests? I can\'t find a tool for that on the web.

11条回答
  •  心在旅途
    2020-12-22 17:02

    Coverage Report →

    a) Run all the tests and enable coverage --> go test ./... -coverprofile coverage.out

    b) Get coverage for individual functions as well as overall coverage → go tool cover -func coverage.out

    c) See the lines covered and the ones not covered by your tests → go tool cover -html=cover.out -o coverage.html. Open the coverage.html file hereby generated in the browser and analyze the detailed coverage info.

提交回复
热议问题