ginkgo
ginkgo copied to clipboard
How to programmatically stop Ginkgo execution on test failure?
I'm looking for a way to programmatically stop the execution of a test run if a certain assertion fails.
Background: It's an assertion I'm running in an AfterEach, and I know that if it fails once, it will definitely fail on all subsequent executions.
Note that this more nuanced than running ginkgo with -failFast, as it's only one particular failure that will cause this behavior.
I guess you could do something like:
var bailOut bool
BeforeEach(func() {
if bailOut {
Skip("bailing out")
}
})
AfterEach(func() {
if badThingHappened() {
bailOut = true
}
})
That would work, but pollute all my output with Skipped messages. I was wondering if you'd consider exposing a StopTestRun() method or so.
I think that's a good feature request. At the moment @onsi is working on Ginko 2.0 which will have more sophisticated control over test execution. It might make sense to add it as part of that work.
The feature request makes sense to me - the tricky bit is orchestration when running in parallel. One node will need to signal to all other nodes to shut down. Not at all impossible, but the only reason that this isn't straightforward. I'll add it to the 2.0 list.
V2 now provides AbortSuite which solves for this use case. It works when running in series or in parallel and will immediately end test execution. V2 is in beta now and I'd love for folks to use it and send me feedback. Docs for using the beta are here.