Unit testing 如何在Go子测试中添加超时?
我目前正在使用Go子测试并行运行多个测试。类似这样的事情-Unit testing 如何在Go子测试中添加超时?,unit-testing,testing,go,Unit Testing,Testing,Go,我目前正在使用Go子测试并行运行多个测试。类似这样的事情- func TestGroupedParallel(t *testing.T) { for _, tc := range testCases { tc := tc // capture range variable t.Run(tc.Name, func(t *testing.T) { t.Parallel() if got := foo(tc.in)
func TestGroupedParallel(t *testing.T) {
for _, tc := range testCases {
tc := tc // capture range variable
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
if got := foo(tc.in); got != tc.out {
t.Errorf("got %v; want %v", got, tc.out)
}
...
})
}
}
当我使用timeout标志时,它会终止所有并行运行的测试。有没有办法让每个子测试都超时?谢谢 不,超时是一个全局超时。@radu matei问题是:“有没有办法让每个子测试都超时?”答案是:没有。为什么这不是一个答案?嗨,@Volker,很抱歉用错误的方式标记了它!我删除了评论,并对你的回答投了赞成票。谢谢