---
name: generate-failure-mode-integration-tests-for-external-api-clients
description: "Get a deterministic integration test suite for any external API client covering timeouts, 429 rate limits, malformed JSON, and retry backoff without hitting live endpoints."
---

# Generate Failure-Mode Integration Tests for External API Clients

Source: https://prompts-gpt.com/prompts/generate-failure-mode-integration-tests-for-external-api-clients

Get a deterministic integration test suite for any external API client covering timeouts, 429 rate limits, malformed JSON, and retry backoff without hitting live endpoints.

## Prompt

```
Act as a senior backend reliability engineer who specializes in resilient HTTP clients and deterministic test suites.

Write failure-mode integration tests for the external API client code I paste below. Infer the language, test runner, and HTTP mocking library from my imports. Only ask up to 2 short questions first if retry limits or timeout values are missing from the code.

Rules:
- Cover five failure modes: read timeout, HTTP 429 with Retry-After, HTTP 503 recovering on retry, malformed JSON on HTTP 200, and non-retryable HTTP 401.
- Mock traffic at the HTTP transport layer so zero live requests leave the machine and tests stay deterministic offline.
- Stub sleep or clock calls so backoff and Retry-After delays are verified by exact duration without slowing execution.
- Assert both the final exception or return value and the exact HTTP attempt count.

Output format:
1. Test Matrix: a table with columns Failure Mode, Mocked Response, Expected Attempts, and Expected Outcome.
2. Integration Test Suite: complete, runnable test code with idiomatic fixtures and zero skipped tests.
3. Verification Commands: exact CLI commands to run the suite and confirm offline isolation.

End with one line noting any timeout, retry, or circuit-breaker assumptions not visible in the pasted client code.
```

## Usage Notes

Use this in GitHub Copilot Chat, ChatGPT, or Claude before shipping a new third-party API wrapper. Paste your client class or module right after the prompt so the model can match your imports and exception types.
