httptest.NewRequest与http.NewRequest:在测试中使用哪个,为什么?

Golang has these two similar libs http and httptest and they both have the NewRequest func.

Why do we even need the httptest.NewRequest if http.NewRequest does it all?

If I need to create a multipart/multiform request for my tests, which one do I need to use?

As indicated in the documentation, httptest.NewRequest "returns a new incoming server Request, suitable for passing to an http.Handler for testing", while http.NewRequest "returns a Request suitable for use with Client.Do or Transport.RoundTrip." So, if you're passing the request directly to the handler in a unit test, use httptest.NewRequest, and if you're executing a full round-trip using http.Client, use http.NewRequest.