4

I have inherited a Go project that consists of a lot of common files, a library of sorts, two executables, and theoretically a test suite. The test suite is being written after the fact. But I dislike the only way I've found of setting up is rather unpalatable

I'm using Ginkgo, and this is my starting directory structure

  • component1/component1.go
  • component2/component2.go
  • cmd1/cmd1.go
  • cmd2/cmd2.go
  • project_suite_test.go
  • component1_test.go

Each cmd?.go file will be compiled into a separate executable.

What I would like is a multi-file test suite, usually one file per component. Where do I put the files so that go test will find and run all of them, without leaving them here in the root of the project?

Savanni D'Gerinel
  • 2,379
  • 17
  • 27

3 Answers3

2

ginkgo init and ginkgo bootstrap will set up your tests. ginkgo -r will run all your tests recursively.

jww
  • 97,681
  • 90
  • 411
  • 885
Jean
  • 670
  • 1
  • 5
  • 14
1

Reason: Ginkgo command will only work if you have actually bootstrap your project via ginkgo.

Options: To use that you have to go to your test dir in terminal and run

ginkgo init : To Initialise project:

ginkgo bootstrap : This will generate new file with test suite config

ginkgo or ginkgo test : this will now be able to run tests based on your new generated file because that's what it is trying to search.

Alternatively:

If you like to keep your tests in a sub-folder, say test, then running

go test ./...

will attempt to run tests in every folder, even those that do not contain any test, thus having a ? in the subsequent report for non-test folders.

Running

go test ./.../test

instead will target only your test folders, thus having a clean report focused on your tests folders only.

you can alternatively use 'go run $(ls *.go)' to run all the files in a given folder. Notice you have regular expression within () braces.

In-case you want to run test in different path update path as per your desired dir in the regular expression

Ishan Kumar
  • 21
  • 1
  • 9
0

You can use go test ./... in the root and it will go into child folders and execute the tests:

component1/component1.go
component1/component1_test.go
component2/component2.go
component2/component2_test.go
cmd1/cmd1.go
cmd1/cmd1_test.go
cmd2/cmd2.go
cmd2/cmd2_test.go
OneOfOne
  • 95,033
  • 20
  • 184
  • 185