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
| func TestFunctionUnderTest(t *testing.T) { testCases := []struct { name string input string expect string wantErr bool errContains string }{ {name1, input1, expect1, wantErr1, errContains1}, {name2, input2, expect2, wantErr2, errContains2}, {name3, input3, expect3, wantErr3, errContains3}, }
for _, tt := range testCases { tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() actual, err := FunctionUnderTest(tt.input) if tt.wantErr { require.ErrorContains(t, err, tt.errContains) assert.Nil(t, actual) } else { compareFunction(t, tt.expect, actual) } }) } }
|