Avatar ·

How to properly organize and run tests in Go for packages in nested subdirectories?

Hello everyone! I'm learning Go and encountered a problem when writing tests for a project that has a structure with subdirectories. My project looks like this: ``` myapp/ ├── main.go ├── handlers/ │ ├── user.go │ └── user_test.go ├── models/ │ ├── user.go │ └── user_test.go └── utils/ └── helpers.go ``` In the file `handlers/user_test.go` I'm trying to import functions from `utils/helpers.go`, but when running `go test ./...` from the project root, the tests fail with an error like "undefined: SomeFunction" or "package myapp/utils is not in GOROOT". If I run `go test` from inside the `handlers/` folder, the tests work, but only if they don't have imports from my other packages. I've read that Go finds tests automatically, but I can't figure out how to properly link tests in subdirectories.