有没有办法将断言与作证联系起来?

Is there a way to chain asserts with testify?

我真的很喜欢 testify 给 go test 带来的东西。但是,我仔细阅读了文档,但没有看到有关如何处理多个断言的任何信息。

Go 是否处理 "first failure",在第一个错误断言处失败的意义上,还是它只关注测试方法中的最后一个断言?

您可以使用 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
}