4 ms·
I think the difference is mocks carry tests while Stubs are dumb fakes. I think the problem is the choice of words. Maybe mocks should actually be called "spi
by aikah 10y ago
I think the difference is mocks carry tests while Stubs are dumb fakes.
I think the problem is the choice of words. Maybe mocks should actually be called "spies" instead and stubs "fakes".
- dpark 10y agoThat terminology makes much more sense, especially the "spies" part. Personally, I tend to think of stubs as being super basic. A stub class for me returns default values or throws NotImplemented or something as simple as possible. It doesn't maintain meaningful state. Mocks for me are generally simplified implementations like an in-memory store that replaces a DB. Frameworks like Moq have muddied my definition though because they call things mocks when they only return canned data. Building a real mock (fake) with real state using Moq tends to be a pain.
- gary_bernhardt 10y agoSpies are a different thing: they allow any interaction, recording it all so that you can inspect it layer. Python's "mock" library, for example, is mostly a spy library.
- dpark 10y ago> Python's "mock" library, for example, is mostly a spy library. It's almost as if the experts don't all agree with this terminology. Edit: This was a bit too snarky, but truthfully, I don't see evidence in the field that these definitions are widely used. I see evidence that an very small crowd is using these terms and asserting their correctness. Meanwhile the rest of the industry thinks anything they use as a "double" in a test is a "mock". Even the people writing widely-used mocking libraries aren't using this terminology consistently.