Stand-ins for testing
Imagine testing a checkout without charging a real card. A test double can stand in for the payment service, making the test safe and predictable.
A stub gives a prepared answer, such as “payment approved”. A mock checks that the checkout sent the right request. A fake does the job in a simpler way, such as a database that keeps records only while the test runs.
Check how the parts work together
Stand-ins make tests quick to repeat, but they may behave differently from the real service. A test that only checks calls to a mock may miss a wrong result. Teams also run broader tests with realistic systems to check that the parts work together.