通过"go test"在第一次测试失败时停止 [英] Stop on first test failure with `go test`

查看:90
本文介绍了通过"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.

推荐答案

Go 1.10添加新的标志 failfast 进行测试:

Go 1.10 add a new flag failfast to go test:

新的go test -failfast 标志会在任何测试失败后禁用运行其他测试.请注意,允许与失败的测试并行运行的测试.

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

但是,请注意,这在 cross 软件包中不起作用: https://github.com/golang/go/issues/33038

However, note this does not work across packages: 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 test"在第一次测试失败时停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆