Which dependency failures can a stub reproduce, and which need a real test environment?
Mock a dependency when you need to reproduce rare delays, error responses or retries on demand. Use a staging integration to establish that real components can authenticate, exchange the intended messages and store compatible state. Keep a few real-boundary checks to expose assumptions that a stub can accidentally make permanent.
Make the delayed callback repeatable
Give a disposable order a unique reference and configure the stub to delay its callback until after the application’s timeout. Assert that the order is pending, then completes exactly once when the callback arrives. A configurable stub gives the team control over the timing and payload. Record both so the test can explain which state changed first.
| Failure of interest | Controlled stub | Staging integration |
|---|---|---|
| Callback arrives late | Set the precise delay and assert the interim state. | Observe timing under the available test environment. |
| Callback repeats | Deliver the same event twice with one ID. | Confirm how the real provider identifies redelivery. |
| Provider changes a status field | A hand-authored fixture may keep the old value. | Compare the real response with the consumer contract. |
| Test data cleanup | Reset the stub and local records each run. | Use supported test accounts and record cleanup ownership. |
Detect a trustworthy-looking stale stub
Run the actual staging provider’s supported flow on a test account and inspect the returned field names, version and final status on both sides. A fixture can accurately model last month’s payload while missing a changed status today. Update the fixture against the provider contract and keep real credentials out of recorded examples.