When you have pulled in a module, into your project, how do you run test cases within that module?
ie I have done:
go get my.repo.com/repo/mymodule
And then try to test something in it:
server> go test src/my.repo.com/repo/mymodule/my_test.go
# command-line-arguments
src/my.repo.com/repo/mymodule/article_test.go:4:2: cannot find package "mymodule" in any of:
Are we supposed to check out our modules separately and test that way? I can't quite work out what to do. It seems that when I go run
it knows how to find the module I have fetched, but when I go test
, it "can't find it" in the path.
go test
expects packages, not folders relative to $GOPATH
.
So leave out the leading src/
and the trailing file name, and it'll work:
go test my.repo.com/repo/mymodule
If the current directory is the package folder you want to test, you can even omit it, eg
cd $GOPATH/src/my.repo.com/repo/mymodule
go test
For reference see Command go / Test packages , also run
go help test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.