1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| func TestAdd(t *testing.T) { ret := Add(1, 2) want := 3 if ret != want { t.Errorf("测试不通过 期望:%v 结果:%v", want, ret) } }
func Test2Add(t *testing.T) { type tt struct { num1 int num2 int want int } m := map[string]tt{ "t1": {num1: 1, num2: 2, want: 3}, "t2": {num1: 4, num2: 2, want: 6}, "t3": {num1: 5, num2: 5, want: 10}, } for k, v := range m { t.Run(k, func(t *testing.T) { ret := Add(v.num1, v.num2) if ret != v.want { t.Errorf("期望:%#v, 结果:%#v", v.want, ret) } }) } }
|