dongyi1015 2017-06-21 19:56
浏览 30
已采纳

将仅在测试文件中引用的测试代码编译为二进制文件吗?

I am wondering what code will be compiled into the go binary if you compile a binary using go build ./... . This will compile a binary that has a cli program. For this cli program, I have test code and non test code. I currently have several flavours of test code:

  • foo_test.go in package foo_test
  • foo_internal_test.go in package foo
  • testutil.go in package testutil that provides test utility functions

No test code is actually referenced in the non test code. The testutil functions are only imported in the test files.

If the test code is infact compiled into the binary , how much of a problem is this?

  • 写回答

1条回答 默认 最新

  • douquan1953 2017-06-21 20:00
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?