Will go test code only referenced in test files be compiled into the binary?

I believe that if you have an init() function in an otherwise unreachable file, it will still be linked into the executable.

_test.go files would be still excluded.

This bit us when we had some test helper code that was not in _test files. One had an init() function which ran on the executable startup.


A go binary only includes code reachable from its main() entry point. For test binaries main() is the test runner.

As to "how much of a problem" it is if it were included... none. It would increase the binary size and compilation time somewhat but otherwise have no impact - code that isn't executed, by definition, does nothing.