How do I have go test several/packages/...
stop after the first test failure?
It takes some time to build and execute the rest of the tests, despite already having something to work with.
Go 1.10 add a new flag failfast
to go test:
The new go test -failfast
flag disables running additional tests after any test fails. Note that tests running in parallel with the failing test are allowed to complete.
To speed-up the build phase you can run
go test -i several/packages/...
before the tests to build and install packages that are dependencies of the test.
To stop after the first failure you can use something like
go test several/packages/... | grep FAILED | head -n 1
Use os.Exit(1).
func TestFoo(t *testing.T) {
if err := foo(); err != nil {
t.Errorf("foo failed: %v", err) // Mark the test as failed.
os.Exit(1) // Cancel any further tests.
}
}