Hacker News new | ask | show | jobs
by henrikeh 2313 days ago
Just a question. Do you imply that the mock of a device should simulate/emulate the entire behavior of the device? Because you definitely don't need to do that and it would, of course, be a vast and hard-to-justify endeavor.

You only need to _mock_ the object, that is emulate behavior on a small scale.

1 comments

Yes and no.

It depends on what we are testing.

It can actually be worse than useless to rely on the "perfect world" of unit testing. I have had a nasty shock, when switching from mocked behavior to real-world behavior. I write about that here: https://medium.com/chrismarshallny/concrete-galoshes-a5798a5...

I'm not going to argue against your experience and from reading the article it seemed like you made the right call. Perfect world testing is indeed a failure, but I would say that "imperfect" world testing is exactly where mocking is beneficial, because it can reliably produce all sorts of anormal behavior. But again, it obviously depends on the situation and circumstances, and good design probably removes more errors than good testing.