Home >Backend Development >Golang >How to Exclude Vendor Package Tests When Running `go test`?

How to Exclude Vendor Package Tests When Running `go test`?

DDD
DDDOriginal
2024-12-14 20:54:31529browse

How to Exclude Vendor Package Tests When Running `go test`?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn