003
測試
吐槽別人家的,go語言採用表格驅動測試
- 測試數據和測試邏輯混在一些
- 出錯信息不明確
- 一旦一個數據出錯測試全部結束
表格驅動測試
test:=[]struct{
a,b,c int32
}{
{1,2,3},
{0,2,0},
{0,0,0},
{0,0,0},
{-1,1,0},
{math.MaxInt32,1,math.MinInt32},
}
for _,test:= reange tests {
if actual:=add(test.a,test.b); actual!=test.c{
// 測試提示
}
}
- 分離測試數據和測試邏輯
- 明確出錯信息
- 可以部分失敗
主題測試文章,只做測試使用。發佈者:Walker,轉轉請注明出處:https://walker-learn.xyz/archives/6738