Fatalf records a formatted test failure and immediately stops the current test function. Use it when continuing would make later checks invalid or unsafe. section 2.3 section 2.3.1
Use Fatalf when:
- A required operation returns an error and the remaining assertions depend on its success. section 2.3.1
- Continuing could trigger an unsafe operation, such as dereferencing a nil result. section 2.3.1
- A failure should stop only the calling test; other tests continue independently. section 2.3
Stop after Parse fails
func TestParse(t *testing.T) { got, err := Parse("https://github.com/inancgumus") if err != nil { t.Fatalf("Parse(%q) err = %q, want <nil>", uri, err) } // Safe to inspect got here. }
Choose Errorf when later checks remain meaningful. In a table-driven test, however, Fatalf stops the whole test function and skips every remaining case. section 2.3.1 section 2.4.4
