牧羊人nacy
assert.IsType来自https://medium.com/@sebdah/go-best-practices-testing-3448165a0e18的片段:func TestDivision(t *testing.T) { tests := []struct{ x float64 y float64 result float64 err error }{ { x: 1.0, y: 2.0, result: 0.5, err: nil }, { x: -1.0, y: 2.0, result: -0.5, err: nil}, { x: 1.0, y: 0.0, result: 0.0, err: ErrZeroDivision}, } for _, test := range tests { result, err := divide(test.x, test.y) assert.IsType(t, test.err, err) assert.Equal(t, test.result, result) }}