How to measure code coverage in Golang?

前端 未结 11 2057
花落未央
花落未央 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 16:52

    If you like to see the uncovered lines by function directly in a terminal I rewrote the cover tool for this purpose. It's available at https://github.com/gregoryv/uncover.

    Usage

    go get -u github.com/gregoryv/uncover/...
    go test -coverprofile /tmp/c.out
    uncover /tmp/c.out
    

    Screenshot

提交回复
热议问题