go build 有效但 go test 没有

标签 go

下面是我的项目结构:

/user/home/go/src/github.com/my_go_proj
                                       /main.go
                                       /mypackage
                                                 /service.go
                                                 /service_test.go

GOPATH points to /user/home/go
cd /user/home/go/src/github.com/my_go_proj
go build ---> This works and creates the `my_go_proj` executable.
go test
?       github.com/my_go_proj   [no test files]
go test github.com/my_go_proj/mypackage
go build gopkg.in/tomb.v2: no buildable Go source files in 
FAIL    github.com/my_go_proj/mypackage [build failed]

go test ./...
?       github.com/my_go_proj   [no test files]
go build gopkg.in/tomb.v2: no buildable Go source files in 
FAIL    github.com/my_go_proj/mypackage [build failed]

如何运行 go test 以在 mypackage 中运行 service_test.go 测试?

更新:更新了 go test ./...

的行为

最佳答案

要测试所有子目录,请使用:

$ go test ./...

来自Relative import pathsCommand go文档:

Relative patterns are also allowed, like go test ./... to test all subdirectories. See 'go help packages' for details on the pattern syntax.

关于go build 有效但 go test 没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34093333/

相关文章:

go - golang的 "range interface"是如何在内部运行的?

golang 练习 :images missing at method

go - 如何在 app.yaml 中为 Go 传递运行参数?

assembly - 堆栈变量在去?

assembly - 如何在golang中使用汇编代码中定义的函数?

go - 如何更改水牛路由器记录的消息的优先级

shell - 如何为 go bin 提供命令

performance - epoll整合的优势

go - Hugo - 呈现自定义内容类型的 ListView

google-app-engine - 去包冲突