Home > Article > Backend Development > How Can I Include External Package Function Coverage in Go Test Reports?
Including Coverage for Functions in External Packages
In a Go project, coverage reports may exclude functions defined in packages other than the tested package. To address this issue when functions in an external package (db) are called from a function in the tested package (api), adjust the testing command to incorporate the coverpkg flag.
By including the following flag when running the coverage test:
-coverpkg=./...
the coverage report will extend to encompass all packages in the project. The updated command becomes:
go test -coverpkg=./... coverprofile=coverage.out ./...
This expanded command ensures that when analyzing coverage, the test also considers functions defined in external packages that are called by the tested code, providing a more comprehensive and accurate coverage report.
The above is the detailed content of How Can I Include External Package Function Coverage in Go Test Reports?. For more information, please follow other related articles on the PHP Chinese website!