gpt4 book ai didi

go - 如何使用 go test -run 运行特定的 golang 测试

转载 作者:IT王子 更新时间:2023-10-29 00:43:26 29 4
gpt4 key购买 nike

我在这里做错了什么?我只想运行这个 ConnectionPoolTest.TestNew,无论我尝试什么,我都会返回“没有要运行的测试”

:go test  --check.list *.go |grep Connectio
ConnectionPoolTest.TestNew
:go test --run ConnectionPoolTest *.go
ok command-line-arguments 0.005s [no tests to run]
:go test --run ConnectionPoolTest.TestNew *.go
ok command-line-arguments 0.005s [no tests to run]

最佳答案

如果你想运行一个特定的测试,你可以像下面这样运行

package main

import (
"testing"
"github.com/stretchr/testify/assert"
)

func TestA(t *testing.T) {
assert.True(t, true)
}

func TestB(t *testing.T) {
assert.True(t, false)
}

运行测试:

$ go test -run B
--- FAIL: TestB (0.00s)
Error Trace: a_test.go:13
Error: Should be true
FAIL
exit status 1
FAIL test 0.004s
$ go test -run A
PASS
ok test 0.003s
shahriar@Kite ~/g/s/test>

-运行标志

-run regexp
Run only those tests and examples matching the regular expression.
For tests the regular expression is split into smaller ones by
top-level '/', where each must match the corresponding part of a
test's identifier.

关于go - 如何使用 go test -run 运行特定的 golang 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48465080/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com