我正在尝试改进我的 Golang 测试。我正在读这个:https ://ieftimov.com/post/testing-in-go-failing-tests/我使用t.Fatal("message")了很多,而我应该使用以下组合:t.Fail()
t.Logf()那么为什么在地球上没有一个电话会导致测试失败并记录原因呢?有没有办法让我将这样的方法添加到 test.Testing 实例?我只想做:t.FailWithReason("the reason the test failed")这是否存在,如果不存在,我可以以某种方式添加它吗?
1 回答
富国沪深
TA贡献1790条经验 获得超9个赞
查看测试包的文档和源代码。
该文档有一个典型使用示例:
func TestAbs(t *testing.T) {
got := Abs(-1)
if got != 1 {
t.Errorf("Abs(-1) = %d; want 1", got)
}
}
的文档t.Errorf是:
// Errorf is equivalent to Logf followed by Fail.
这与您所说的非常相似:
t.Fail()
t.Logf()
添加回答
举报
0/150
提交
取消
