httptest

Go's standard library package of helpers for testing HTTP code, such as a recorder that captures what a handler writes.

In more detail

httptest.NewRequest builds a request and httptest.NewRecorder captures the status, headers and body, so a handler can be tested in memory with no port or network. httptest.NewServer starts a real local server when a client needs one.

Example

recorder := httptest.NewRecorder()
health(recorder, httptest.NewRequest(http.MethodGet, "/health", nil))

Related terms

Taught in

References