DEV Community

Maesi
Maesi

Posted on

Testing Kafka Workflows Without Kafka — With Playwright & Mokapi

Event-driven systems are powerful — but testing them can feel heavy.

Spinning up a Kafka cluster, checking if specifications are met, producing test input, and reading results from topics… it adds a lot of overhead, especially in CI pipelines.

What if you could test Kafka workflows without running a Kafka cluster?

That’s exactly what Mokapi enables.


Why This Matters

Testing event-driven workflows usually means juggling infrastructure:

  • Running a local or containerized Kafka broker
  • Making sure topics and schemas match the spec
  • Setting up test producers and consumers
  • Verifying results at the topic level

For end-to-end workflow tests, this slows you down. With Mokapi, you can skip the cluster and use a Kafka-like REST API for producing and consuming records — perfectly aligned with your AsyncAPI specs.

The Testing Scenario

Let’s walk through a realistic workflow.

In our system:

  • A foreign system sends a command to document.send-command (Kafka topic).
  • Our backend consumes this command, simulates sending the document, and then publishes a result to document.send-event.

Here’s how we test this with Playwright + Mokapi:

  1. Produce input — Playwright sends a Kafka record into document.send-command using Mokapi’s REST API.
  2. Backend processes the command — our Node.js backend consumes the command and publishes the outcome into document.send-event.
  3. Verify the result — Playwright retrieves the new record from document.send-event via Mokapi’s REST API and checks the documentId and status.

This gives us full end-to-end confidence without running Kafka.


Example Setup

👉 The full example project is available here: mokapi-kafka-workflow.

  • Backend: Node.js consumer + producer
  • Mokapi: mocks the Kafka cluster using AsyncAPI
  • Playwright: drives the test by producing and verifying messages

Playwright doesn’t open a browser UI in this case — it’s simply used as a testing framework with clean assertions and easy integration into CI.


Conclusion

This example shows how to build an end-to-end Kafka workflow test with Playwright and Mokapi:

  • ✅ Simple setup — no Kafka broker required
  • ✅ Produce and consume messages via REST
  • ✅ Works seamlessly in CI/CD pipelines

And this pattern scales: you can expand it to multiple backends and topics while keeping tests easy to write and maintain.

With Mokapi, testing Kafka workflows becomes lightweight, reliable, and spec-driven.

🔗 Read the full tutorial on mokapi.io

Top comments (0)