How to ignore generated files from Go test coverage

You could strip the generated code from the cover profiles:

go test . -coverprofile cover.out.tmp
cat cover.out.tmp | grep -v "_generated.go" > cover.out
tool cover -func cover.out

Depending on the used tools this can be implemented easily in the pipeline/make.

Leave a Comment