4 ms·
External systems dependencies are better handled with stubs and fakes than mocks, in my experience.
by readthenotes1 4y ago
External systems dependencies are better handled with stubs and fakes than mocks, in my experience.
- Tainnor 4y agoThat really depends on the case in question and on the particulars of the codebase. I wouldn't recommend mocking http libraries, database calls etc. - that usually leads to madness and impenetrable test setups. I would rather recommend to either use fake implementations (e.g. in-memory DB) or to only integration-test the boundaries of your interaction with the external system (that might or might not be hard to achieve). But I do like the pattern of wrapping calls to external APIs through a layer that I control - so that, for example, I may just write mailer.sendMessage(message) - and then that mailer interface seems like a good candidate for mocking.