Modern QA2026Pattern 2: Callback Capture — tiles
Log inJoin
70 / 89 · 04 API & Contract Testing with AI · Asynchronous Testing Patterns← prev⊞ allnext →☰ Read as one page

11.3Pattern 2: Callback Capture

Spin up a temporary HTTP server, register it as a webhook target, and capture incoming calls.

# See webhook-and-sqs-testing.md for the WebhookCapture implementation

def test_payment_webhook(webhook_server, payment_service):
    """Verify payment completion triggers a webhook."""
    payment_service.register_webhook(
        url=f"{webhook_server.url}/payment-complete",
        events=["payment.completed"]
    )

    payment_service.process_payment(order_id="ord-1", amount=99.99)

    call = webhook_server.wait_for_call(timeout=15)
    assert call is not None, "Payment webhook not received"
    assert call["body"]["order_id"] == "ord-1"
    assert call["body"]["amount"] == 99.99
    assert call["body"]["status"] == "completed"

When to use: Webhook testing. Verify that an external system calls your endpoint.