loading...
GO 断言(testify)
Published in:2024-09-26 |

Go标准包中为什么没有断言,官方在FAQ里面回答了这个问题。

官方说是为了防止程序员在错误处理上偷懒。

但其实个人感觉引入的话可读性更高嘿嘿

基本使用方法大概如下

1
2
3
4
5
func TestTestify(t *testing.T){
a := assert.New(t)
a.Equal(v, want)
a.Nil(err,"Information ...")
}
Prev:
Go test中运行指定的benchmark
Next:
GO time.Duration
catalog
catalog