Testing Multiple Directories with go test
In the Go testing framework, go test typically executes tests in a single directory containing *_test.go files. However, there may be instances where you need to test across multiple directories for a comprehensive project coverage.
To achieve this, you can use the following commands:
go test ./...
This command instructs go test to run tests in the current directory and all of its children directories, recursively.
go test ./tests/... ./unit-tests/... ./my-packages/...
This command allows you to specify multiple directories where you want the tests to run.
go test foo/...
If your project is organized in a hierarchy, you can use this command to run tests for all directories prefixed with the foo/ import path.
go test foo...
This shortened version achieves the same result as the previous example, by matching all import paths that start with foo.
go test ...
Finally, to test all the tests in your $GOPATH, you can use this command, which includes all the Go modules you have installed in your system.
The above is the detailed content of How Can I Run `go test` Across Multiple Directories?. For more information, please follow other related articles on the PHP Chinese website!