Testing All Files Except Vendor Packages in Go Projects
When working on a Go project with a complex structure, it can be tedious to run tests individually for each component. This article provides a solution for running go test on all test files in a project while excluding the files within the vendor package.
The project folder structure mentioned in the question includes various subdirectories, including vendor. Within these subdirectories, test files are identified with the suffix _test.go. The goal is to exclude test files in the vendor package while running go test.
Initially, using the command go test ./... appeared to include vendor test files. This is because previously, the wildcard pattern ... did not exclude the ./vendor directory. However, as of Go 1.9, the pattern now excludes the ./vendor directory.
Therefore, the simplest solution is to run the following command:
go test ./...
This will run go test on all test files in the project, excluding the test files within the vendor package.
The above is the detailed content of How to Run `go test` on All Files Except Vendor Packages in Go?. For more information, please follow other related articles on the PHP Chinese website!