WireMock is an HTTP server simulator for stubbing and mocking external API dependencies in integration tests. It supports exact and pattern-based URL matching, request verification, record-and-playback from real APIs, and latency simulation for resilience testing.
0 / 5 completed
1 / 5
What is WireMock and in what testing scenario is it most commonly used?
WireMock is an HTTP mock server that allows you to stub external API dependencies in integration tests. Instead of calling real third-party services (payment gateways, email providers, external APIs), tests interact with WireMock which returns configured responses.
2 / 5
A developer configures a WireMock stub using stubFor(get(urlEqualTo('/api/users/1')).willReturn(aResponse().withBody('{"name":"Alice"}'))). What happens when the app calls GET /api/users/2?
WireMock stubs use exact URL matching by default with urlEqualTo(). A request to /api/users/2 does not match the stub defined for /api/users/1, so WireMock returns a 404 with an error body explaining that no matching stub was found.
3 / 5
What is WireMock's record and playback feature used for?
WireMock's record mode proxies requests to a real backend and saves the request-response pairs as stub mappings. You can then switch to playback mode to serve the recorded responses without the real backend, enabling offline testing and deterministic test environments.
4 / 5
A developer uses WireMock's verify() method in a test. What does this assertion check?
WireMock's verify() method asserts that specific HTTP requests were made to WireMock during the test. For example, verify(1, postRequestedFor(urlEqualTo('/api/orders'))) checks that exactly one POST was made to /api/orders, ensuring the application called the expected endpoint.
5 / 5
Which WireMock feature allows simulating delayed or slow API responses to test timeout handling?
withFixedDelay(milliseconds) in WireMock adds a configurable delay before returning the response, simulating slow network conditions or slow backend processing. Combined with withChunkedDribbleDelay() for streaming responses, you can test application timeout handling and retry logic.