Golang Test Coverage

Report Go test coverage for all packages. TIL note about golang. Use when working with golang and the user mentions test coverage or related topics. Use when this capability is needed.

tomevault-io Updated

File contents

Report Go test coverage for all packages

Write coverage to file cover.out and then print a report based on it

go test ./... -coverprofile cover.out
go tool cover -func cover.out

Same as above but a one-liner using a tmp file, which is rm-ed at the end

OUT=$(mktemp); go test ./... -coverprofile="$OUT" && go tool cover -func="$OUT"; rm "$OUT"

Source: kfet/til — distributed by TomeVault.

tomevault-io/skills-registry/tree/main/kfet--til--golang-test-coverage commit 7fbe0cf367

Frequently asked questions

npx skillmds@latest add tomevault-io/golang-test-coverage