下面是我的项目结构:
/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 paths节Command 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/