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

In a table-driven test, a developer runs subtests in a loop using `t.Run`. They add `t.Parallel()` inside each subtest to speed things up. With the loop written as below (Go 1.21), what is the classic bug?

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