In Go, is there a way to abort a suite of tests early if one of them fails?
I am using stretchr/testify suites but this just builds on the basic go testing functionality.
Some options I have considered:
- I looked at setting testing.failFast but it is not exported.
- os.Exit() is not recommended, because it could mess up the test output among other things.
- stop on first failure is not sufficient as the first failure might not be in a critical test
I can add my own flag and then add to each test:
if criticalTestFailed {
t.skipTest()
}
But this is repetitive and annoying boilerplate to add to each test. What I want is something like:
func (suite *MySuite) TestCritcalTest() {
t := MySuite.T()
defer func() {
if t.Failed() {
MySuite.SkipRemainingTests() //does not exist
}
}()
// some tests here...
}
Is there a common practice here?