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

In a table-driven test, what is the purpose of capturing the loop variable and calling t.Parallel() inside t.Run, and what changed in Go 1.22?

for _, tt := range tests { tt := tt // pre-1.22 t.Run(tt.name, func(t *testing.T) { t.Parallel() got := Do(tt.in) if got != tt.want { t.Errorf("got %v want %v", got, tt.want) } }) }