Home > Backend Development > Golang > How to Run `go test` on All Files Except Vendor Packages in Go?

How to Run `go test` on All Files Except Vendor Packages in Go?

DDD
Release: 2024-12-09 00:44:10
Original
416 people have browsed it

How to Run `go test` on All Files Except Vendor Packages in Go?

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 ./...
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template