I am creating some unit tests for my code, for the first time in Go.
I have successfully had tests running where all files are dumped in the same directory (eg main.go package having a function being tested by main_test.go). By running the command
go test, the tests and associated code are successfully executed.
It seems however more prudent to me to keep the test packages/files separate from my actual project files, so I moved the main_test.go file into a sub-directory titled Unit_tests. I am now baffled as to how you get the tests to run again.
I have tried (in CLI) to run:
go test /home/user/go_directory/project/main.go
however this simply results in an error stating I cannot use an absolute path. I wouldn’t think I should have to have the test in $PATH, as this may then be confused with other tests/packages.
What is the generally accepted practice with regard to where and how to store unit test files? Where should I be storing them? how do I execute them when not stored in the same directory as my project?
I am also not sure, when executing the command
go test xyz.go whether xyz specifies the unit test itself, or the package under test. nobody clarifies this online.
I am using: VS Code 1.47.3 Ubuntu 18.04 (all up to date) Go Version go1.15.2 linux/amd64