Back to questionsDoes the subtest
JuniorTheoryCommon
Does the subtest TestHalf/4 run?
func TestHalf(t *testing.T) {
for _, n := range []int{2, 3, 4} {
t.Run(fmt.Sprint(n), func(t *testing.T) {
if n%2 != 0 {
t.Fatalf("%d is odd", n)
}
})
}
}Yes: t.Fatalf stopped only the TestHalf/3 subtest
- Expecting
t.Fatalfto stop the whole TestHalf: insidet.Runit stops only its own subtest, and the loop goes on to 4. - Expecting
go testto stop at the first failure: without-failfastit runs every test and subtest and reports all the failures.
- How would you run only the subtest
TestHalf/4from the command line? - What would change if the loop called
t.Fatalfdirectly, withoutt.Run?