Utilizing Local Files for Go Testing
When testing Go applications that require access to local files, the approach to handling these files is a crucial consideration. Here are the options and best practices for local file testing in Go:
In most cases, the second option is recommended as it provides a cleaner and more structured approach to local file testing in Go:
testing/... | |--test_files_here | |--main.go | `--main_test.go
You can then read the contents of the files located within the testing/... directory during your tests. This method simplifies maintenance and ensures that all files necessary for testing are conveniently accessible in a designated location.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3