RejectedSoftware Forums

Sign up

Recommendations for testing route handlers?

This can possibly be very simple issue but I can't find any easy way to create dummy HTTPServrResponse/HTTPServerRequest so that I could unittest my rendering handlers. Theoretically it should be trivial, as all it needs is preparing HTTP fields in request and providing output stream in response (which later can be checked to verify output). But I can't seem to find anything like that.

Any suggestions? Are there any other recommendation for adding unittest coverage for handlers?

Re: Recommendations for testing route handlers?

Am 25.07.2015 um 00:15 schrieb Dicebot:

This can possibly be very simple issue but I can't find any easy way to create dummy HTTPServrResponse/HTTPServerRequest so that I could unittest my rendering handlers. Theoretically it should be trivial, as all it needs is preparing HTTP fields in request and providing output stream in response (which later can be checked to verify output). But I can't seem to find anything like that.

Any suggestions? Are there any other recommendation for adding unittest coverage for handlers?

You are looking for createTestHTTPServerRequest and
createTestHTTPServerResponse in vibe.http.server :)

Re: Recommendations for testing route handlers?

Ahha, nice!

How one is supposed to use it to actually verify rendering though? In vibe.d own tests it is only used to verify routes and because of chunked nature of vibe.d request handlers resulting memory stream for dummy response object will look simply like this:

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked

(empty body)