4 ms·
I find the distinction between “fake”, “stub” and “mock” very useful when making decisions about my own code, but I’ve basically given up on using it to communi
by tomstuart 6y ago
I find the distinction between “fake”, “stub” and “mock” very useful when making decisions about my own code, but I’ve basically given up on using it to communicate because I never find myself dealing with anyone who cares about the different meanings. Most people I know use “mock” to refer to any kind of test double.
- hyko 6y agoDon’t give up :) ‘mock’ has indeed become an umbrella term for all test doubles, but the other terms still have specific technical meanings, so it’s still worth using them correctly. If you’re working with technical people who don’t care about technical details then that’s probably not a good sign!
- k__ 6y agoI had the impression it's generally frowned upon replicating systems in an incomplete way when debugging/testing. When would you recommend this practice? And which of the three would you recommend for what?
- mumblemumble 6y agoSo, first off, a disclaimer: I'm a partisan of classical TDD. With that out of the way, I would recommend using a test double in exactly one kind of situation: When it's genuinely awkward to use the real thing. Concrete examples include talking to a third-party API, testing for error conditions that are difficult or impossible to reliably organically produce, and when the real dependency hasn't actually been implemented yet. As for the different kinds of test doubles, Fowler has a concise overview at https://martinfowler.com/bliki/TestDouble.html https://martinfowler.com/bliki/TestDouble.html that is just about the clearest explanation I've seen of the different kinds and what they're used for.
- Person5478 6y ago> With that out of the way, I would recommend using a test double in exactly one kind of situation: When it's genuinely awkward to use the real thing. THANK YOU. I'm actually pretty staunchly anti-mocking (and anything similar). I think too many developers start thinking of testing as the goal rather than as the means. What this means to me is I don't care if it's technically an integration test vs a unit test, I care that it tests _REALITY_. There are times when the isolation given by mocking can be useful, but I submit it's useful far far less often than many claim. And your examples are a good use as well. But imo trying to mock everything is mostly mental masturbation only with long-term maintenance costs.