Reputation: 118540
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.
Upvotes: 55
Views: 30363
Reputation: 846
Go 1.10 added 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.
However, note this does not work across packages: https://github.com/golang/go/issues/33038
Here's a workaround:
for s in $(go list ./...); do if ! go test -failfast -v -p 1 $s; then break; fi; done
Upvotes: 71
Reputation: 9559
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
Upvotes: -6