3

I have inherited a very large, very old golang codebase. I'm trying to get coverage stats and most of the tests are testing across packages.

If I run go test ./... the tests pass.

If i run go test -coverpkg=./... ./... then the tests fail because all the the init() functions are executed during the tests. (It's failing in a bunch of cobra cmd that don't even have tests). The init() do things that cause the tests to fail.

Is there a way to get the init() to not happen when collecting coverage just like a normal test run?

Shiny
  • 111
  • 1
  • 4
  • Is there an answer? https://stackoverflow.com/questions/43409919/init-function-breaking-unit-tests/43410591 – outdead Nov 26 '21 at 05:56

0 Answers0