Run Tests in All Packages

Life can be simple when all your Go files are in the root folder. But when a project gets a bit bigger, you may want to store much of the logic in packages. The issue comes when our usual command of go test then no longer picks up our tests.

This post is a super-quick way of running your tests across these folders/packages.

1
go test -v ./...

We’ve add in the -v flag too, which isn’t required, but will list out the tests it’s running.

Here’s our example:

1
2
3
4
5
6
$ go test -v ./...
?       my-project       [no test files]
=== RUN   TestGoFunc
--- PASS: TestGoFunc (0.00s)
PASS
ok      my-project/pkg/mypackage  (cached)