Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to have a single suite that will run tests in sub packages? #1350

Open
tzvatot opened this issue Feb 6, 2024 · 2 comments
Open

Comments

@tzvatot
Copy link

tzvatot commented Feb 6, 2024

We want to have the following structure:

- main_test.go
-  a
   -  a_test.go
-  b
   -  b_test.go

Where main_test.go contains the main entry point of the test suite, and the 2 sub packages a and b contains the actual tests.
Is that something we can achieve with ginkgo or is there a limitation with golang test framework/ginkgo in achieving this?

Currently when running this structure, anything inside a_test_.go and b_test.go are not invoked.

@onsi
Copy link
Owner

onsi commented Feb 6, 2024

yes this can be done and some projects (e.g. kubernetes) organize their tests in this way. The trick is to define your specs within the a and b packages:

- main_test.go
- a
    - a.go //drop _test
- b
    - b.go //drop _test

these tests can then be imported in main_test.go:

import (
    _ “project/path/to/a”
    _ “project/path/to/b“
)

func TestMainTest(t *testing.T) {
    …
    RunSpecs(t, “Main Test”)
}

any Ginkgo DSL commands in a and b will be invoked and added to the testing tree in main and run.

@onsi
Copy link
Owner

onsi commented Feb 6, 2024

FWIW I personally don’t usually write tests this way and just give each package its own test suite and run ginkgo -r. But there are certainly cases on big projects where it makes sense to organize things this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants