Our test suite leans on a handful of third-party APIs, and it’s become the flakiest part of CI. When their sandbox is slow or down, our builds fail for reasons that have nothing to do with our code, and rate limits during test runs make it worse. So I want to properly mock these dependencies instead of calling them live.
The thing I keep going back and forth on is how faithful the mocks need to be. Hand-written stubs are simple but drift from the real API over time and give you false confidence. Recording real responses and replaying them stays truer to actual behavior but needs tooling to manage. There’s a genuine tradeoff between simplicity and fidelity.
I was reading up on [url=https://keploy.io/blog/community/what-is-api-mocking]api mocking tools[/url] to see how people automate the record-and-replay side rather than maintaining stubs by hand, which seems like the sane approach once you have more than a couple of dependencies.
How does your team mock external services in tests? Hand-written mocks, recorded traffic, a dedicated tool, or contract testing? And how do you keep the mocks from silently drifting out of sync with the real API?
