Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何在Go子测试中添加超时?_Unit Testing_Testing_Go - Fatal编程技术网

Unit testing 如何在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)

我目前正在使用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); got != tc.out {
                t.Errorf("got %v; want %v", got, tc.out)
            }
            ...
        })
    }
}

当我使用timeout标志时,它会终止所有并行运行的测试。有没有办法让每个子测试都超时?谢谢

不,超时是一个全局超时。

@radu matei问题是:“有没有办法让每个子测试都超时?”答案是:没有。为什么这不是一个答案?嗨,@Volker,很抱歉用错误的方式标记了它!我删除了评论,并对你的回答投了赞成票。谢谢