You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question/Feature Request: Ability to run a BeforeEach for ALL specs in a project #1629
We have multiple Describe suites, that live in separate files in the same project. For each one of them we have added a BeforeEach that helps us skip tests if they have previously run and were successful (a way to speed up our testing pipelines).
// this is mandatory when checking skipped test
// the spec hash is helpful to debug and manually skip tests
BeforeEach(func(specContext SpecContext) {
e2eSuite.SetupSpec(specContext, specContext.SpecReport(), true)
})
We have the collaboration problem that some engineers write new files and forget to include this block, and we have multiple projects like these. So I am wondering if there is a way to run one BEFORE EACH for all Its within the same project, so we can write it only once..
Hey there - yes, if you put the BeforeEach at the top level of any of the files in the testing package (or any library imported by the testing package) it will register as a BeforeEach that runs below any descendant specs (which will be all the specs):
Note the var _ = .... Go does not allow bare function invocations at the top level but it does allow invocations that lead to assignments. In this case we simply ignore the assignment with var _.
Hi! I found this via Google as I'm trying to do something similar - instead of skipping tests, I am setting up a gRPC server for integration tests. I'm storing the server in a global variable like this:
I don't think this is thread-safe though and I would like to run the suite with parallel execution. What's the best way to achieve this in Ginkgo? I am aware of BeforeSuite / SynchronizedBeforeSuite but they run once per suite while I'm trying to run once per spec
hey @csirmazbendeguz what you've got will work just fine. When you invoke ginkgo -p to run on parallel ginkgo spins up and orchestrates multiple processes. no shared memory - no thread safety issues:
Activity
onsi commentedon Dec 29, 2025
Hey there - yes, if you put the
BeforeEachat the top level of any of the files in the testing package (or any library imported by the testing package) it will register as aBeforeEachthat runs below any descendant specs (which will be all the specs):Note the
var _ = .... Go does not allow bare function invocations at the top level but it does allow invocations that lead to assignments. In this case we simply ignore the assignment withvar _.pablocalvo-zh commentedon Jan 13, 2026
Yeah but we have about 20 files per suite. I wanted to avoid re-writing it everytime. I wanted to see if there was a 1 time thing..
onsi commentedon Jan 13, 2026
You only need to call it once. In one file (typically the
X_suite_test.gofile - it will run at the top level before every spec in the suitecsirmazbendeguz commentedon Mar 23, 2026
Hi! I found this via Google as I'm trying to do something similar - instead of skipping tests, I am setting up a gRPC server for integration tests. I'm storing the server in a global variable like this:
I don't think this is thread-safe though and I would like to run the suite with parallel execution. What's the best way to achieve this in Ginkgo? I am aware of
BeforeSuite/SynchronizedBeforeSuitebut they run once per suite while I'm trying to run once per speconsi commentedon Mar 23, 2026
hey @csirmazbendeguz what you've got will work just fine. When you invoke
ginkgo -pto run on parallel ginkgo spins up and orchestrates multiple processes. no shared memory - no thread safety issues:https://onsi.github.io/ginkgo/#spec-parallelization