logoalt Hacker News

vips7Lyesterday at 11:28 PM3 repliesview on HN

I've found that most of the time that if you need to mock, you probably just need to do an integration test.


Replies

jeremyjhtoday at 3:07 AM

I agree. I mostly only use mocks for external service dependencies (apart from primary application database), or library features that are very problematic to use in test. A lot of code simply should not be unit tested - if an integration test can cover the same paths its far better in the long run. Performance can become an issue but it is easier to deal with that than to spend so much time maintaining and debugging mock constructs.

asa400today at 1:34 AM

I can’t concur with this enough.

I’ve been on projects where mocking _literally made the project less reliable_ because people ended up “testing” against mocks that didn’t accurately reflect the behavior of the real APIs.

It left us with functionality that wasn’t actually tested and resulted in real bugs and regressions that shipped.

Mocking is one of these weird programmer pop-culture memetic viruses that spread in the early 2000s and achieved complete victory in the 2010s, like Agile and OOP, and now there are entire generations of devs who it’s not that they’re making a bad or a poorly argued choice, it’s that they literally don’t even know there are other ways of thinking about these problems because these ideas have sucked all the oxygen out of the room.

show 1 reply
sfn42today at 2:23 AM

Mocking and integration tests are not mutually exclusive. I often use mocks in my integration tests. Some things can be integration tested, some things can't. Sone things you just need to mock.