Go code
func TestAdd(t *testing.T) {
got := Add(2, 3)
if got != 5 {
t.Fatalf("got %d, want 5", got)
}
}Line-by-line explanation
- The test name begins with Test.
- T reports test failures.
- Got stores the actual result.
- The condition compares expected behavior.
- Fatalf reports a useful failure.
Expected output
PASS
ok example.com/projectThis is the expected result.
Store tests in files ending with _test.go and run them with go test ./....