
Just documenting another concept into a mental model.
Imagine you are preparing for a game of tennis, but you don’t have any opponents to practice with. This is an external dependency.
How do you practice your game, you can’t bounce it of the wall, it will be predictable. An automatic tennis ball machine is what you need.
It will throw balls at you at varying speeds at different angles, much like a real player would. But a human opponent will still surprise you no matter how much you practice playing against a ball machine.
In Test Driven Development mocking frameworks are playing that exact same role, for example replacing an external API dependency. Hard coding values would be like bouncing the ball of a wall for tennis practice. Mock will provide you the ability but a real API at production still might have surprises for you.
I mainly work in .net and here are the tools I use to do testing…