go - 如何自动启用测试在包内并行运行?

标签 go testing parallel-processing

我想在包中并行运行测试。我们知道testing.Parallel function使我们能够并行运行包中的两个测试,但是有没有一种方法可以自动使包中的所有测试并行运行而不调用 t.Parallel() ?

例如,我是否可以将任何标志放入 go test 中,以使具有函数签名 func(t *testing.T) 的所有测试并行运行?

最佳答案

这来自commit f80d8fb和 Go1(2011 年 10 月)

选项(--parallel)是debated at the time ,但很快就被拒绝了:

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.

关于go - 如何自动启用测试在包内并行运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56927397/

相关文章:

opengl - 显示 2 个半透明对象的公共(public)部分?

facebook - 如何创建用于开发目的的测试帐户

go - 如何将以毫秒为单位的字符串时间(hh :mm:ss. xxx)转换为time.Time?

go - 将 GOPATH 设置为我的工作空间的原因是什么?

http - 如何使用 Golang http.ResponseWriter 将 HTML 字符串显示为网页?

java - Selenium 在作为套件运行测试时找不到元素

.net - 为什么我在 F# 中的并行性能很差

python - Xvfb 多显示器并行处理?

parallel-processing - go是使用共享内存还是分布式计算

go - 检查来自 os.Remove 的错误消息