https://kotlinlang.org logo
#http4k
Title
# http4k
b

Ben Tilford

11/29/2021, 11:47 PM
Is there a way to setup
RequestContext
for unit tests that are using a mocked request?
j

James Richardson

11/30/2021, 8:40 AM
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

s4nchez

11/30/2021, 9:33 AM
Precisely. Requests/Responses are values and not expected to be mocked.
👍 1
b

Ben Tilford

11/30/2021, 3:49 PM
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

s4nchez

11/30/2021, 3:52 PM
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

Ben Tilford

11/30/2021, 3:54 PM
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

s4nchez

11/30/2021, 4:00 PM
d

dave

11/30/2021, 7:35 PM
It's practically obese by comparison 😂
b

Ben Tilford

11/30/2021, 11:22 PM
What is needed to create the RequestContext during tests?
a: use the same context 😆
17 Views