Project | Web & API
Testing Third-Party APIs with WireMock
A checkout client for a payment and a shipping API, tested against WireMock over real HTTP: request matching, response templating, stateful retry scenarios, all four network faults, delays, JSON mappings, and record and replay.
59 tests prove what a sandbox cannot show on demand: dropped connections, rate limits and timeouts end as an unknown payment rather than a double charge, and eight deliberate client bugs were all caught.
Evidence checked 5 Nov 2026 | CI run on main
On this page
Problem and purpose
A provider's sandbox will not drop a connection halfway through a response, or answer 429 on the second attempt, when a test needs it to. Those failures are where integrations go wrong, and in payments they can charge a customer twice. This project makes every one of them repeatable, in seconds, with no Docker and no network.
Architecture
JUnit tests ──► CheckoutService ──► ShippingClient ──GET /v1/rates────► WireMock (carrier)
│
└───────────► PaymentClient ──POST /v1/payments──► WireMock (provider)Technology and tools
| Area | Tools |
|---|---|
| Client | Java 21, JDK HttpClient, Jackson: a payment client with retries and a shipping client with a fallback |
| Mocks | WireMock 3.13: one server per API on a free port, strict matching, an unmatched request fails the test |
| Tests | JUnit 6, AssertJ: 59 tests from 35 test methods, with case IDs in the method names |
| CI | GitHub Actions on Java 21, a table of test classes in the job summary, weekly scheduled run |
Engineering decisions and approach
- A payment has three outcomes: after a timeout the client cannot know whether the money moved, so the result is unknown, never failed
- One idempotency key per order, not per attempt, so a retry cannot become a double charge
- Retry only what can change: 429 and 5xx, not other 4xx answers
- Shipping degrades and payment does not: one attempt, then a flat rate marked as estimated
- Stub objects, the page object of API mocking: tests read as behaviour and WireMock stays in one class per API
Test scope and execution approach
Project-specific checks and execution details documented in the repository:
- Request matching on headers, query parameters and exact JSON bodies
- Response templating: the answer is built from the request
- Stateful scenarios for retries, Retry-After handling and exponential backoff, with the waits themselves asserted
- All four WireMock network faults, and fixed delays against real timeouts
- Stubs as JSON mapping files with priorities, and record and replay
- Eight deliberate client bugs, all caught; one survived at first, because WireMock decodes + and %20 alike, and the test now checks the raw URL
- Design notes, 35 manual test cases and 60 interview questions on API mocking (Markdown + PDF)
Results with dated evidence
Historical repository or workflow evidence
CI run on main
59 tests prove what a sandbox cannot show on demand: dropped connections, rate limits and timeouts end as an unknown payment rather than a double charge, and eight deliberate client bugs were all caught.
Evidence checked: | Open dated evidence
Evidence explorer
Static screenshots are labelled as images; dated workflow links identify the execution evidence and its check date.
Static material from the public repository. The linked verification record was checked 2026-11-05; that date is not a screenshot capture date.
Dated workflow record
Evidence checked 2026-11-05. Open CI run on main
Local setup and execution
mvnw.cmd verify :: 59 tests, Java 21 or newer, no Docker
mvnw.cmd test -Dtest=PaymentRetryTest#tc122* :: one case by its IDWorkflow and reports
Known limitations
- The APIs are invented, modelled on common payment and carrier APIs
- A mock cannot notice a real API changing: contract tests cover that, as in the Pact project
- HTTP/1.1 on localhost: TLS, proxies and real network timing are not covered
- The payment and shipping APIs are invented; a mock cannot notice a real API changing, which is what contract tests are for.