【发布时间】:2017-08-21 01:40:59
【问题描述】:
我真的很喜欢 testify 为 go test 带来的东西。但是,我翻阅了文档,没有看到有关如何处理多个断言的任何内容。
Go 是否处理“第一次失败”,即它在第一个错误断言处失败,还是只关注测试方法中的最后一个断言?
【问题讨论】:
我真的很喜欢 testify 为 go test 带来的东西。但是,我翻阅了文档,没有看到有关如何处理多个断言的任何内容。
Go 是否处理“第一次失败”,即它在第一个错误断言处失败,还是只关注测试方法中的最后一个断言?
【问题讨论】:
您可以使用与 assert 具有完全相同接口的 testify/require,但它会在失败时终止执行。 http://godoc.org/github.com/stretchr/testify/require
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
)
func TestWithRequire(t *testing.T) {
require.True(t, false) // fails and terminates
require.True(t, true) // never executed
}
func TestWithAssert(t *testing.T) {
assert.True(t, false) // fails
assert.True(t, false) // fails as well
}
【讨论】: