Slide 22
Slide 22 text
Table-driven tests
func TestToUpper(t *testing.T) {
// Table-driven tests
candidates := []struct {
src, expected string
}{
{"foo", "FOO"}, {"bar", "BAR"},
}
for _, c := range candidates {
actual := strings.ToUpper(c.src)
if c.expected != actual {
// should be good error messages.
t.Fatalf("Expected %v, but got %v\n", c.expected, actual)
}
}
}