Home > Article > Backend Development > Can I Organize Go Tests in Sub-Directories?
Can I Organize Tests in Sub-Directories in Go?
Yes, you can organize tests in sub-directories in Go. This allows you to keep your workspace cleaner and organize your tests more effectively.
How to Organize Tests in Sub-Directories
To organize tests in sub-directories, create a sub-directory named "tests" or "test" within the package directory. Place your test files in this sub-directory.
Running Tests in Sub-Directories
To run tests in sub-directories, use the following command:
go test ./...
The ./... notation specifies that all packages and their sub-directories should be tested.
Note:
Alternative Considerations
While organizing tests in sub-directories can be beneficial, some prefer to keep test files alongside the main source files for easier access. Additionally, with Go 1.20, coverage tooling now supports collecting profiles from larger integration tests.
Conclusion
Organizing tests in sub-directories in Go is possible and offers flexibility in test organization. However, the choice depends on individual preferences and the specific needs of your project.
The above is the detailed content of Can I Organize Go Tests in Sub-Directories?. For more information, please follow other related articles on the PHP Chinese website!