3 ms·
What situation would require to mock a function ?
by Arkadir 12y ago
What situation would require to mock a function ?
- mercurial 12y agoMaybe I'm not interested in testing what the function does? But yes, for pure functions, it's kind of a weak argument. More generally, you can't really swap a different implementation in place.
- JackMorgan 12y agoI answered this in my other answer to you: https://news.ycombinator.com/item?id=7709395 https://news.ycombinator.com/item?id=7709395 It's a common misconception that interfaces are the only way to do polymorphism, because that's usually the only way in Java.
- koide 12y agowhen you require unit tests to finish quickly for functions doing io or otherwise time consuming processes. this being a good idea or not I'll leave to the threads about dhh's tdd article
- Arkadir 12y agoI would argue that functions have no business performing global side-effects in the first place --- these things are better expressed as state encapsulators (such as objects) anyway.