unit testing - httptest.NewRequest vs http.NewRequest: which one to use in tests and why? -


golang has these 2 similar libs http , httptest , both have newrequest func.

why need httptest.newrequest if http.newrequest all?

if need create multipart/multiform request tests, 1 need use?

as indicated in documentation, httptest.newrequest "returns new incoming server request, suitable passing http.handler testing", while http.newrequest "returns request suitable use client.do or transport.roundtrip." so, if you're passing request directly handler in unit test, use httptest.newrequest, , if you're executing full round-trip using http.client, use http.newrequest.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -