Home >Backend Development >Golang >How to Exclude Generated Files from Go Test Coverage?
Excluding Generated Files from Go Test Coverage
When running tests for a Go package with go test -coverprofile=cover.out
Stripping Generated Code from Coverage Profiles
Pipeline Integration
Depending on the tools used, this process can be easily integrated into your build/test pipeline. For example, if using Make, you could include the following steps:
test: go test -coverprofile cover.out.tmp . cat cover.out.tmp | grep -v "_generated.go" > cover.out tool cover -func cover.out
By excluding generated files from the coverage calculation, you can obtain more accurate coverage metrics that focus on your manually written code.
The above is the detailed content of How to Exclude Generated Files from Go Test Coverage?. For more information, please follow other related articles on the PHP Chinese website!