003
Testing
Complaining about others' approaches, the Go language uses table-driven tests.
- Test data and test logic are mixed together
- Unclear error messages
- All tests end once one data point is incorrect
Table-driven tests
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{
// 测试提示
}
}
- Separate test data and test logic
- Clear error messages
- Can fail partially
主题测试文章,只做测试使用。发布者:Walker,转转请注明出处:https://walker-learn.xyz/archives/6738