【发布时间】:2018-01-27 00:25:10
【问题描述】:
我在这里做错了什么?我只想运行这个 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]
【问题讨论】:
-
go test需要包,而不是 go 文件,要过滤要运行的测试,请使用-run X,其中X是一个正则表达式,它将与测试名称匹配。运行go help test了解更多详情;和Go tool: Test packages;和Go tool: Description of testing flags。 -
我不明白。是否有一种简单的方法可以自行运行该测试。我的正则表达式应该与 -check.list 的测试输出相匹配
-
要单独运行该测试,请转到其文件夹,然后键入:
go test -run TestNew。如果您有其他名称包含TestNew子字符串的测试,请运行go test -run ^TestNew$。 -
这就是我认为它会工作的方式,但它不是 go test --run ^TestNew$ testing: warning: no tests to run PASS go test -check.vv --run TestNew testing: warning:没有测试可以运行 PASS
-
只需一个破折号:
-run,并确保您在包的文件夹中,否则您还必须传递包名称。
标签: go