从根项目文件夹运行go测试

I have to take over a go project from a colleague and I've never touched Go before and it doesn't have tests so I've started to add them but I cannot run them.

The go command for running tests is go test but it doesn't seem to run at the root level.

My project structure is:

/project/main.go
/project/engine/*.go
/project/api/*.go

If I cd into either engine or api, and run go test it works but not in the root folder.

cd /project
go test

 ?      /project    [no test files]

Is there anyway to run all tests from the root?

You can use the ... (ellipsis) operator to test all subpackages of the current package. Like that: go test ./....

There are other solutions that you might want to try later if you do something more sophisticated, like using the list tool. Like that (for example): go test $(go list ./... | grep [regex]). That's useful to exclude the vendor directory from your tests.

Another thing you may want to know about is the gt command that can be found here https://godoc.org/rsc.io/gt and add caching to the go test command.

Finally, don't hesitate to read https://blog.golang.org/cover to get informations about code-coverage analysis in golang.