-
Notifications
You must be signed in to change notification settings - Fork 267
Description
Hi.
What is the best approach for outside in testing with Giraffe? Or am I bringing too much baggage with me from the OO world, and the preferred FP way is to do something else instead?
Context:
I'm coming to F# from C# and MVC and writing micro services.
I usually prefer testing these services from the outside (Use the Test Server to create a http client bound to the service under test, and making http calls to that service, asserting the expected response), as this allows loose coupling of the tests from the service, and allows for aggressive refactoring of the service internals if required, w/o the need to refactor the tests.
I do utilise more low level unit style testing if and when required...it's just not my default behaviour.
Often, when the service I maintain makes an outbound request to a separate downstream service, the above test strategy is achieved by injecting a delegating handler into the HTTP client that will make the request, and that handler intercepts the outgoing call, returning a stubbed response. I am then able to confim the behaviour of my own service, based on how the downstream service behaves in a particular way: Ie; 200/ok on the happy path scenario, 5XX when the downstream times out or errors etc.
This delegating handler is injected into the HTTP Client during configuration of the TestServer/host, so is never injected into production code, only when the tests are running.
I've not been able to work out how to achieve this with F#. Not seen any examples of folks doing this.
So I wondered if maybe this is not seen as the way of doing things in the FP world