Comparison
Null objectvsTest double
Null object
instead of returning null you returned something that implements the interface and does nothing, and the null checks disappeared.
Supplying a valid object with neutral behaviour in place of a null reference, so callers do not have to branch. It works beautifully for collaborators with no meaningful absence — a no-op logger, an empty collection, a permissive policy — and badly where absence really is a case the caller must handle, because it turns a loud failure into a silent nothing. That is the line between it and an option type, which makes absence explicit rather than invisible.
Full entry →Test double
you swap the real collaborator for a stand-in, because the real one is slow, remote, or has side effects you cannot have in a test.
The umbrella term for any object substituted for a real dependency in a test: stubs, mocks, fakes and spies are all test doubles. Naming the specific kind matters because they answer different questions — some make a test possible, others make an assertion. Calling everything a mock is why test reviews go in circles.
Full entry →