Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock code reducing code coverage

I am working with Golang and using mockhiato to generate mocks for all interfaces. This tool generates mocked implementation in mocks.go file within the same package. I can't rename mocks.go to mocks_test.go as this mock file is consumed by other packages.

The problem is that these mocks files are counted by go coverage tool and thus reducing my code coverage percentage for the package.

I am looking a good workaround so that my code coverage will not show bad numbers.

like image 476
Rahul Garg Avatar asked Mar 30 '26 21:03

Rahul Garg


1 Answers

The best thing in this case would be to move the mocks to their own dedicated package which would have no test coverage. This would remove their impact on code that you actually want coverage data on.

like image 90
Andrew Hare Avatar answered Apr 02 '26 14:04

Andrew Hare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!