Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

that is a fake. A mock is a device for verifying you called the expected funchtions. A fake emulates the api. Importantly if you change funcioms the fake will still pass if they mean the same - think of write which might take a buffer+length [C style], a list or a string (often there would be more than 10 variations)



i learned something new today, thanks

--

following in that theme, just doing some digging [1] turns up the following for those that might have been confused like i was:

  Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.

  Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).

  Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.

  Spies are stubs that also record some information based on how they were called. One form of this might be an email service that records how many messages it was sent.

  Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
[1] https://www.martinfowler.com/articles/mocksArentStubs.html




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: