注意,你可以运行go test“recursively”:你需要列出你想测试的所有包。
原文链接:https://www.f2er.com/go/187718.html如果您是Go项目的根文件夹,请键入:
go test ./...
‘。/ …’符号在“command go
”的“Description of package lists”部分中描述:
An import path is a pattern if it includes one or more “...
” wildcards,each of which can match any string,including the empty string and strings containing slashes.
Such a pattern expands to all package directories found in the GOPATH
trees with names matching the patterns.
As a special case,x/...
matches x
as well as x
‘s subdirectories.
For example,net/...
expands to net
and packages in its subdirectories.
如果你将_test.go文件保存在一个子文件夹中,’go test。/ …’命令将能够接受它们。
但:
>您将需要使用包的名称为导出的变量和函数(在测试中使用)添加前缀,以便测试文件能够访问包导出的内容。
>您不会访问非导出的内容。