Is there a way to setup `RequestContext` for unit ...
# http4k
b
Is there a way to setup
RequestContext
for unit tests that are using a mocked request?
j
Why would you use a mocked request? One of the main design goals appears to be that mocks are not necessary for testing anything with http4k, just use a real request. myhandler(Request(GET, Uri.of("/path")).body("whatever"))
s
Precisely. Requests/Responses are values and not expected to be mocked.
👍 1
b
Working with existing code
For a test that does depend on the request context do you run the full application then?
(ahh see the answer in the 1st response)
s
Most http4k applications are composed in such way that you can pick a part of it (http handler + key filters) and test that without much need for mocking.
I appreciate that’s not the usual style a lot of people are used to though.
b
Yeah, having taken a break from java and done Node for a couple years the pattern makes sense. Not how the codebase I inherited did things though.
I didn’t realize the request object was so lightweight though
s
d
It's practically obese by comparison 😂
b
What is needed to create the RequestContext during tests?
a: use the same context 😆