Home  >  Article  >  Backend Development  >  How Can I Include External Package Function Coverage in Go Test Reports?

How Can I Include External Package Function Coverage in Go Test Reports?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-25 18:49:14748browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn