Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumGotable-driven testsSingle-choice MCQ

This table-driven test was written for Go 1.21. Why might several subtests all report the values of the last case?

tests := []struct{ name string; in, want int }{ {"a", 1, 2}, {"b", 2, 4}, {"c", 3, 6}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { t.Parallel() if got := Double(tc.in); got != tc.want { t.Errorf("%d: got %d", tc.in, got) } }) }