Avoid inaccurate tests: Use httptest when testing HTTP handlers in Go/Golang

In Go, testing HTTP handlers is more work than testing regular functions. Inputs must be wrapped in HTTP requests, and responses are written to http.ResponseWriter , rather than being returned directly. To make matters worse, handlers expect server-side requests, while it&rsquo;s easy to mistakenly construct client-side requests. You&rsquo;d almost give up on testing your handlers altogether.…