logoalt Hacker News

wiseowiseyesterday at 10:33 PM2 repliesview on HN

> But third-party IO is exactly the thing you'd want to mock.

You write an adapter.


Replies

deepsunyesterday at 10:57 PM

No, some other library classes accept only their own, not my adapter.

Not mentioning of course needless copy-pasting dosens of members in the adapter. And it must be in prod code, not tests, even though it's documentation would say "Adapter for X, exists only for tests, to be able to mock X".

show 1 reply
throwaway7375yesterday at 11:11 PM

Once you start writing adapters you need a way to instantiate them to choose between implementations, and factories is often used for this. Then you might generalize the test suites to make the setup easier and you end up with the infamous FactoryFactory pattern.