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.
Agent prompt for ChatGPT and Claude
You get: Test Matrix, integration Test Suite and verification Commands
Prompt
mkdir -p .agents/skills/generate-failure-mode-integration-tests-for-external-api-clients && curl -sL "https://prompts-gpt.com/prompts/generate-failure-mode-integration-tests-for-external-api-clients/raw" -o .agents/skills/generate-failure-mode-integration-tests-for-external-api-clients/SKILL.mdSKILL.md
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.Example output
Tips and common edits
Why this works
- Forces transport-layer HTTP mocking so tests never depend on flaky sandboxes or live third-party rate limits.
- Requires stubbing sleep calls and asserting exact attempt counts, catching hidden retry loops without slowing CI.
- Separates retryable 429 and 503 errors from non-retryable 401 and malformed JSON failures in a clear test matrix.
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.
Common edits
- Add a sixth failure mode for HTTP 429 with an HTTP-date Retry-After header if your upstream API uses timestamps.
- Specify your exact mocking library, such as MSW for TypeScript or WireMock for Java, in the first line.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
Parenting & Family
Help an elementary child handle losing or feeling left out
Get practical scripts and emotion-regulation steps to support an elementary-age child after rejection, social exclusion, or losing a game.