My Go app(restfull api service) is growing and i decided to use testing. My choise is Ginkgo/Gomega.
Learning site (http://onsi.github.io/ginkgo/#getting-started-writing-your-first-test) i found that to start test you need
This will create file [your_package]_suite_test in root of package folder. It's Ok.
But then if i want to test some feature or file or package i need again goto the folder and ginkgo generate [test_name] which will create stub test file here.
So, in one moment we will have many messy: files of our app and testing files together in one folder. For example, server.go, server_test.go, auth.go, auth_test.go, and so on.
I want to searate app files and test files. For example i want to create a folder tests in root package and place all tests here. So, when i need to test app i can run go test ./tests
Is it correct pattern to use Ginkgo/Gomega with separate tests folder?
Thanks.
In Go you can run all tests of a given project with a single command regardless of where your test files are located. In a terminal, change to your project base directory and run:
$ go test ./...
In my Go projects I usually have a separate Bash script that will do this for me. You can can place it, for instance, in bin/run_tests.sh
with the following contents:
#!/bin/bash -e
time go test ./... | grep -v '^?'
Make this file executable and then run it:
$ ./bin/run_tests.sh
I don't have a separate test
folder. Judging by most Go projects I see around what developers are going for is having the test file in the same directory where the file being tested is located.