Stop on first test failure with `go test`

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:

Here’s a workaround:

for s in $(go list ./...); do if ! go test -failfast -v -p 1 $s; then break; fi; done

Leave a Comment