| ▲ | 9rx 2 days ago | |||||||
> The domain that exports the API should also provide a high fidelity test double that is a fake/in memory implementation (not a mock!) Not a mock? But that's exactly what a mock is: An implementation that isn't authentic, but that doesn't try to deceive. In other words, something that behaves just like the "real thing" (to the extent that matters), but is not authentically the "real thing". Hence the name. | ||||||||
| ▲ | B-Con 2 days ago | parent [-] | |||||||
There are different definitions of the term "mock". You described the generic usage where "mock" is a catch-all for "not the real thing", but there are several terms in this space to refer to more precise concepts. What I've seen: * "test double" - a catch-all term for "not the real thing". What you called a "mock". But this phrasing is more general so the term "mock" can be used elsewhere. * "fake" - a simplified implementation, complex enough to mimic real behavior. It probably uses a lot of the real thing under the hood, but with unnecessary testing-related features removed. ie: a real database that only runs in memory. * "stub" - a very thin shim that only provides look-up style responses. Basically a map of which inputs produce which outputs. * "mock" - an object that has expectations about how it is to be used. It encodes some test logic itself. The Go ecosystem seems to prefer avoiding test objects that encode expectations about how they are used and the community uses the term "mock" specifically to refer to that. This is why you hear "don't use mocks in Go". It refers to a specific type of test double. By these definitions, OP was referring to a "fake". And I agree with OP that there is much benefit to providing canonical test fakes, so long as you don't lock users into only using your test fake because it will fall short of someone's needs at some point. Unfortunately there's no authoritative source for these terms (that I'm aware of), so there's always arguing about what exactly words mean. Martin Fowler's definitions are closely aligned with the Go community I'm familiar with: https://martinfowler.com/articles/mocksArentStubs.html Wikipedia has chosen to cite him as well: https://en.wikipedia.org/wiki/Test_double#General . My best guess is that software development co-opted the term "mock" from the vocabulary of other fields, and the folks who were into formalities used the term for a more specific definition, but the software dev discipline doesn't follow much formal vocabulary and a healthy portion of devs intuitively use the term "mock" generically. (I myself was in the field for years before I encountered any formal vocabulary on the topic.) | ||||||||
| ||||||||