英文:
Stop on first test failure with `go test`
问题
如何在第一个测试失败后停止go test several/packages/...
命令的执行?
尽管已经有一些测试可以工作,但仍然需要花费一些时间来构建和执行其余的测试。
英文:
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.
答案1
得分: 60
Go 1.10在go test中添加了一个新的标志failfast
:
新的go test -failfast
标志在任何测试失败后禁止运行其他测试。请注意,与失败的测试并行运行的测试允许完成。
然而,请注意这在跨包时不起作用:https://github.com/golang/go/issues/33038
以下是一个解决方法:
for s in $(go list ./...); do if ! go test -failfast -v -p 1 $s; then break; fi; done
英文:
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
答案2
得分: -6
为了加快构建阶段的速度,你可以运行以下命令:
go test -i several/packages/...
在运行测试之前,这将构建并安装测试所依赖的包。
如果想在第一个失败后停止测试,可以使用类似以下命令:
go test several/packages/... | grep FAILED | head -n 1
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论