Test doubles wiremock

From makifbaysal/tasktrooper · View interactive version

Test doubles wiremock is an AI agent skill from the GitHub repository makifbaysal/tasktrooper. Use when a test would otherwise call a real external dependency - replace it with WireMock or an equivalent stub so runs are deterministic, offline, and control the responses

How to use this skill

Skill file

Test Doubles & WireMock

Overview

An automated test that calls a real third-party service (payment gateway, auth provider, partner API) is slow, flaky, costs money, and cannot exercise failure modes on demand. Replace those dependencies with a controllable stub — WireMock for HTTP — so the test owns every response.

Core principle: The system under test is real; its external dependencies are stubbed. You test YOUR code's behavior against controlled inputs, not the third party's uptime.

When to Use / When NOT

WireMock Essentials

Run WireMock as a standalone server or a Testcontainers container; point the app's config for that dependency at its URL.

// stub: the auth provider returns a valid token for a known client
{
  "request":  { "method": "POST", "url": "/oauth/token" },
  "response": { "status": 200, "jsonBody": { "access_token": "test-token", "expires_in": 3600 } }
}

Model the failure paths too — that's the value a real service won't give you on demand:

| Scenario to cover | WireMock stub |

|-------------------|---------------|

| Happy response | 200 + expected body |

| Upstream 5xx | "status": 503 → assert your retry/fallback |

| Timeout | "fixedDelayMilliseconds": 30000 → assert your timeout handling |

| Malformed body | 200 + garbage → assert you don't crash |

| Auth rejected | 401 → assert your error surfaces cleanly |

Rules

Worked Example

Checkout calls an external payment API. To test "payment declined shows an error and does not create an order":

  1. WireMock stub: POST /charge → 402 {"error":"declined"}.
  2. Drive the real checkout flow against it.
  3. Assert: user sees the decline message, no order row was created, and WireMock recorded exactly one POST /charge with the expected amount.

No real card, no real gateway, and the decline path is tested every run.

Common Mistakes

Red Flags

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.