How to measure code coverage in Golang?

前端 未结 11 2052
花落未央
花落未央 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:03

    Inspired by the help menus and other answers to this question, just run:

    f=cover.out; if [ -f $f ]; then rm $f; fi; go test ./... -coverprofile $f && \
    go tool cover -html $f && \
    rm $f
    

提交回复
热议问题