3 ms·
The jargon around all this stuff is terrible. What I would probably write is, like, a fake version of that API, one which runs out of process from the library o
by tomjakubowski 2y ago
The jargon around all this stuff is terrible. What I would probably write is, like, a fake version of that API, one which runs out of process from the library or test, and which can be "programmed" from the test set up -- "expect these requests, serve these responses", etc.
Is that a mock? I don't know. It sure does resemble one, but it doesn't use dependency injection or other runtime tricks which I'd associate with classic "mocks"; it's just another program you write to support the tests. The imperative shell doing I/O needs to be configurable to support this (think a "widgets API base URL"), but that's it.
- ninetyninenine 2y agoThe jargon is terrible because I think you misunderstood my point. You don’t mock period is my philosophy but your talking about mocking an entire api here.
- BoiledCabbage 2y agoYes that still a mock. And thr point is to structure your code in such a way that there is little to no value left in testing that API call independently, because all of the related logic has been tested in a unit test. Once you've done that, you can just run a simple integration or end-to-end test to cover that API. You never need to manually mock it (like you suggested), or use a mocking tool.
- drewcoo 2y ago> that still a mock It's a fake, not a mock. Mocks and fakes are both test doubles. > And thr point is to structure your code in such a way that Sometimes it's not your code. Sometimes you want to change legacy code and want tests to prove that your changes don't break anything. Life would be so much easier if there were just one way to test, wouldn't it?
- bluGill 2y agothat 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)
- andrekandre 2y agoi 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 https://www.martinfowler.com/articles/mocksArentStubs.html