Matt Joiner
Matt Joiner

Reputation: 118540

Stop on first test failure with `go test`

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

Answers (2)

gao
gao

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.

https://golang.org/doc/go1.10

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

kostya
kostya

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

Related Questions