Go Test Execution Exclusion for Vendor Packages
Problem:
In a Go project containing multiple subpackages (e.g., foobar_test.go files), how can one utilize 'go test' to execute all test files while excluding tests within the vendor package?
Solution:
The 'go test' command provides a '-run' option that accepts a regular expression pattern to filter which tests to execute. However, matching only the test identifier can be impractical.
Go version 1.9 introduced an improved wildcard feature that can be leveraged to exclude the vendor directory from test execution. Simply execute:
go test ./...
This wildcard will automatically exclude the './vendor' directory and its subdirectories, effectively isolating tests within the vendor package from execution.
The above is the detailed content of How to Exclude Vendor Package Tests When Running `go test`?. For more information, please follow other related articles on the PHP Chinese website!