dronthpi05943 2019-07-08 01:33
浏览 88
已采纳

如何自动使测试在程序包中并行运行?

I would like to run tests in a package in parallel. We know that the testing.Parallel function enables us to run two tests in a package in parallel, but is there a way to automatically enable all tests in a package to run in parallel without calling t.Parallel()?

For example, are there any flags I can throw into go test to make all tests with the function signature func(t *testing.T) be ran in parallel?

  • 写回答

1条回答 默认 最新

  • douchen7555 2019-07-08 04:52
    关注

    This comes from commit f80d8fb and Go1 (Oct. 2011)

    An option (--parallel) was debated at the time, but quickly rejected:

    Many tests won't work if run in parallel. (Many will, too.)
    The presence of a --parallel flag means scripts and so on will want to turn it on, and tests must be able to protect themselves from erroneous runs.

    I suggest whitelisting individual tests that are knowingly able to run in parallel, and the easiest way to do this is to name them differently.

    I like t.Parallel.
    It's clear which tests are parallel, it's not a global default, so you can apply it just to the tests where it is both appropriate and necessary, and the behavior is great: all the non-parallel run first - meaning the easy ones - and then the parallel ones can chew cpu.

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

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因