跪拜 Guibai
← All articles
Backend · Open Source · Testing

Record Real API Traffic, Auto-Generate Tests: Keploy Hits 19.8K Stars

By 狂师 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Mock maintenance and environment setup stop being the bottleneck when recorded traffic replaces every external dependency; tests run offline in CI with no real database or queue. The work shifts from writing test cases to just running the app, which any team already does daily.

Summary

Keploy records real API traffic as the app runs, then turns those recordings into replayable tests and mocks. Capture happens at the kernel level with eBPF, so no SDK, no code changes, and no test cases to write. Every request, response, database query, and message queue event gets logged; on replay, the app talks to recorded snapshots instead of real infrastructure. That means tests run offline, on any machine, without a database, cache, or third-party service.

The tool covers more than HTTP: Postgres, MySQL, MongoDB, Redis queries, Kafka and RabbitMQ messages, gRPC and GraphQL calls all become recorded mocks. Keploy calls this infra virtualization. It handles the two coverage views separately: developers get statement and branch coverage from recorded traffic, testers get API structure and business scenario coverage. When the recordings aren't enough, `test-gen` uses an AI agent to synthesize edge cases from existing captures and OpenAPI docs.

Setup is a one-liner, and the basic flow is `record` then `test`. Volatile fields like timestamps and random IDs need `templatize` and `normalize`; sensitive data must be scrubbed with `sanitize` before committing. The author's bottom line: the tool is worth trying for teams with many services and tangled dependencies, but the underlying idea, traffic is the test case and dependencies can be replaced by recordings, works even without Keploy.

Takeaways
— 19.8K+ GitHub stars, Apache-2.0 license, written in Go; v3.7.3 released two days before the post.
— Listed in CNCF Landscape and appeared on Trendshift.
— Captures traffic at the kernel level using eBPF, requiring no SDK or code changes to the application.
— Records and mocks Postgres, MySQL, MongoDB, Redis, Kafka, RabbitMQ, gRPC, and GraphQL interactions.
— Generates test cases from real traffic and replays them offline; mocks replace all external dependencies.
— CLI commands: `record`, `test`, `test-gen`, `sanitize`, `templatize`, `normalize`, `export`.
— `test-gen` uses an AI agent to generate edge-case tests from real captures and OpenAPI/Swagger docs.
— Installation via one line: `source /dev/stdin <<<"$(curl -fsSL https://keploy.io/install.sh)"`.
— Requires Linux kernel 5.10+; runs on macOS (Apple Silicon) and Windows (x86-64), and inside Docker/Podman.
— Keploy tests itself with Keploy, showing 75% coverage on its README.
— Snapshot replay fails on volatile fields like timestamps and random IDs; `templatize` and `normalize` handle them.
— Sensitive data must be scrubbed with `sanitize` before committing test artifacts.
— Core CLI is Apache-2.0; Mock Registry, time freezing, and console features require the official cloud service.
Conclusions

Writing API tests is not the hard part; reproducing the full dependency environment is, and Keploy removes that by recording real interactions and replaying mocks, so effort shifts from composing cases to just running the app.

The capture location, eBPF at the kernel, is what lets Keploy record database queries and queue messages that HTTP-level mocks miss.

The idea that real traffic is itself a test suite, and that dependencies can be substituted with recordings, is portable beyond Keploy; teams can adopt it as a testing philosophy without adopting the tool.

Concepts & terms
Infra virtualization
Keploy's term for replacing all real external dependencies (databases, queues, third-party services) with recorded data during test replay, so the app thinks it's talking to the real infrastructure but is actually hitting snapshots from the recording phase.
eBPF
Extended Berkeley Packet Filter, a Linux kernel feature that lets programs run safely in kernel space on network events; Keploy uses it to capture traffic at the kernel level without instrumenting the application.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗