3 ms·
How do you deal with http interactions in test? Do you mock it or maybe save it to disk to replay later?
by leftsidedhorn 9y ago
How do you deal with http interactions in test? Do you mock it or maybe save it to disk to replay later?
- cjsuk 9y agoThat's an integration test really. The clients all have an abstraction around the http endpoints so nothing touches integration in unit tests. The advantage of this is you deal with transfer objects only in the code, no HTTP which would violate separation of concerns. I use HttpMock myself in test cases which fires up an http server for personal projects. We use Wiremock commercially.
- mohaine 9y agoHere is how I handle it 1) Write a test that runs the service and saves output to a file. 2) Mock out the call to just return the data from the file and validate results. 3) If you need variations on this data just modify the file/data (often as part of the test) I usually leave number 1 in the code but disabled since it often relies on remote data that may not be stable. Having the test run more than once is not very beneficial but being able to run it later and see what exactly has changed is great.