Why Event-Driven APIs Are Harder to Test

▶ Watch (3:39)

REST mocking is straightforward: paste a JSON response and call it done. Event-driven systems don’t work that way. Payloads carry timestamps and go stale. Refreshing a messaging queue mid-test is not practical. A static mock that sends “order made at 12” keeps sending that same payload on repeat. The downstream service eventually concludes the data is stale and breaks. Static mocks replay one scenario. Real Kafka queues serve unpredictable ones.

AsyncAPI: The Spec Layer for Event-Driven Mocking

▶ Watch (8:05)

Static mocks return one response, forever. Dynamic mocks need a schema that captures message structure, not just field names. AsyncAPI fills that role for event-driven systems the same way OpenAPI does for REST. It defines channels, message formats, and the producer/consumer interaction. Upload the spec to Microcks and it automatically creates live mocks from every event defined in the file. No separate test infrastructure, no hand-rolled consumers. The spec drives the test, from channel names to payload shape.

Microcks: A Kubernetes-Native Mock Server

▶ Watch (9:03)

Microcks is a CNCF Sandbox project that runs directly inside a Kubernetes cluster. Installing it drops a main pod, a Kafka sidecar, Keycloak for authentication, and MongoDB into a dedicated namespace. Everything sits behind an ingress, accessible at a local URL. The web interface accepts AsyncAPI or OpenAPI specs and generates live mock services immediately on upload. It spins up lightweight containers rather than requiring a dedicated test environment. The demo ran the full stack on a local kind cluster.

Mock Templates: From Hardcoded to Dynamic

▶ Watch (15:53)

Microcks v1.0.1 of the spec sends the same hardcoded values on every tick. The demo showed an order-created event returning the exact payload from the AsyncAPI examples file, unchanged. Version 1.0.2 adds mock templates: values wrapped in double curly braces call built-in functions like randomInt with a min and max range. Upload the updated spec and the Kafka consumer starts receiving a different order ID each time. The mock now matches what a real producer would emit.

Notable Quotes

static mocks cannot replicate the real-time behavior Anushka Saxena · ▶ 7:19

Key Takeaways

  • Static mocks replay one payload endlessly; real event-driven systems never do.
  • AsyncAPI gives event-driven APIs the same spec-driven contract that OpenAPI gives REST.
  • Microcks mock templates use double curly brace syntax to generate random field values per message.

About the Speaker(s)

Anushka Saxena is a Software Application Development Apprentice at Google, working on GCP Databases and MCP Toolbox. She contributes to the CNCF community and completed an LFX mentorship with the CloudNativePG project.

Harshvardhan Parmar is a Software Engineer at YosemiteCrew and a maintainer of Microcks, a CNCF Sandbox project. He participated in Google Summer of Code 2024 and completed an LFX mentorship under Microcks in 2025.