Use `testify/require` when a failed check makes the rest of a Go test pointless. A failed `require` check displays a message and stops that test; a failed `testify/assert` check displays a message but lets it continue. Add both through `go get github.com/stretchr/testify`. section 8.2.1
Listing 8.12 newgame/handler_test.go: Testing Handle
func TestHandle(t *testing.T) {
req, err := http.NewRequest(
http.MethodPost, "/games", nil) #1
require.NoError(t, err)
recorder := httptest.NewRecorder() #2
Handle(recorder, req) #3
assert.Equal(t, http.StatusCreated, recorder.Code) #4
assert.Equal(t, "application/json",
recorder.Header().Get("Content-Type")) #4
assert.JSONEq(t, `{"id":"",...}`,
recorder.Body.String()) #4
}
`require.NoError(t, err)` guards request creation before the handler is called. The response checks use `assert.Equal` and `assert.JSONEq` so multiple results can be checked. section 8.2.1
