Home > Backend Development > Golang > How Can I Run `go test` Across Multiple Directories?

How Can I Run `go test` Across Multiple Directories?

Mary-Kate Olsen
Release: 2025-01-04 08:21:35
Original
613 people have browsed it

How Can I Run `go test` Across Multiple Directories?

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:

  • Testing Current Directory and Subdirectories:
go test ./...
Copy after login

This command instructs go test to run tests in the current directory and all of its children directories, recursively.

  • Testing Specific Directories:
go test ./tests/... ./unit-tests/... ./my-packages/...
Copy after login

This command allows you to specify multiple directories where you want the tests to run.

  • Testing Import Path Prefixed with a Namespace:
go test foo/...
Copy after login

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.

  • Testing Import Path Prefixed with a Namespace (Shortened):
go test foo...
Copy after login

This shortened version achieves the same result as the previous example, by matching all import paths that start with foo.

  • Testing All Tests in the GOPATH:
go test ...
Copy after login

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template