Home > Backend Development > Golang > 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
Release: 2024-11-25 18:49:14
Original
825 people have browsed it

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=./...
Copy after login

the coverage report will extend to encompass all packages in the project. The updated command becomes:

go test -coverpkg=./... coverprofile=coverage.out ./...
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template