Mockzilla logo

Chaos Monkey: Testing Resilience

The Problem: How do you test if your UI handles a 503 Service Unavailable, a 10-second timeout, or a weird API error gracefully? Waiting for the real backend to fail is inconsistent. Asking a backend dev to "break the API for a minute" is a waste of time and productivity.

The Mock-First Solution: Create one mock per failure mode on the same path, each locked to a query parameter. Mockzilla picks the most specific matching mock, so a query string switches the response without touching any backend code.


1. Setting up the Happy Path

Let's say you have a checkout endpoint: POST /api/checkout. Create an Exact mock with no query parameters that returns 200 OK:

{ "status": "success", "order_id": "ord_123" }

2. Creating Chaos Mocks

Create three more POST mocks with the same endpoint, /api/checkout, and Match Type Exact. Give each one a required row in Advanced Options → Query Parameters.

Mock A: The 503 Outage (force_error = true)

  • Status Code: 503
  • Response Body:
{ "error": "service_unavailable", "message": "The payment gateway is currently down." }

Mock B: The "Card Declined" (status = declined)

  • Status Code: 402 (Payment Required)
  • Response Body:
{ "error": "card_declined", "code": "insufficient_funds" }

Mock C: The Timeout (latency = high)

  • Status Code: 200
  • Response Delay (ms): 15000 (15 seconds), under Advanced Options
  • Response Body: the same success JSON as the happy path

A request without these query parameters matches only the happy-path mock. A request with ?force_error=true matches both the happy-path mock and Mock A, and Mock A wins because a required query row adds to its match score.

Wildcard variants are not the right tool here: they choose a response from path captures (the values matched by *), not from query parameters, and they cannot have their own delay.

3. Testing the UI Resilience

Now, you can test your frontend resilience instantly without touching any backend code.

  1. Test Success: Call POST /api/checkout -> Confirm success UI.
  2. Test Error State: Call POST /api/checkout?force_error=true. -> Verify UI shows the correct error message and retry button.
  3. Test Declined Card: Call POST /api/checkout?status=declined. -> Verify UI triggers the 'Payment Failed' animation.
  4. Test UX under Latency: Call POST /api/checkout?latency=high. -> Verify loading spinners appear and don't flicker.

To turn a failure mode off without deleting it, disable that mock.

4. The Result: Robust Products

You are validating the "unhappy paths" of your product on day one. You don't have to wait for production to discover that your app crashes when the payment gateway goes down. You mocked the chaos, built the error handling, and shipped a robust product.

🤖 Do it with AI

"Next to my POST /api/checkout mock, create three more POST /api/checkout mocks with required query parameters: 1. 503 Service Unavailable when force_error=true. 2. 402 Card Declined when status=declined. 3. A 15-second delay when latency=high."