Keploy logo
Bun logo

Keploy as a Bun testing framework

Keploy tests Bun services by recording real HTTP and database traffic from a running process, then replaying it as assertions. There is no module mock to register and nothing to mock by hand, because capture happens below the runtime at the socket.

Generate Bun tests free
keploy record -c "bun run index.ts"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a Bun team

Any Bun service, unchanged

Keploy runs the process you already run with bun. Elysia, Hono and a bare Bun.serve handler all record identically.

  • Bun 1.x
  • Elysia, Hono, Bun.serve
  • Node-compatible packages
  • No bunfig changes
The problem

Why Bun integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing Bun: by hand, with bun test, or with Keploy

bun test describes the exchange by hand and still needs the dependency supplied. Keploy records both halves once and replays them with nothing running.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for Bun vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
orders.test.ts
hand-written
import { test, expect, mock } from "bun:test";
import { handler } from "./orders";
 
// Swapped in the module registry for the whole file.
mock.module("./db", () => ({
findOrder: async () => ({ id: "o-1", total: 4200, status: "NEW" }),
}));
 
mock.module("./payments", () => ({
authorize: async () => ({ status: "AUTHORIZED" }),
}));
 
test("confirms an order", async () => {
const res = await handler(new Request("http://localhost/orders/o-1/confirm", {
method: "POST",
}));
 
expect(res.status).toBe(200);
});

bun:test mocks the module, so the Postgres driver never runs.

bun test1–2 hours
orders.integration.test.ts
tool-assisted
import { test, expect } from "bun:test";
import { SQL } from "bun";
import { handler } from "./orders";
 
// A real Postgres, so the job needs one running.
const db = new SQL(process.env.DATABASE_URL!);
await db`insert into orders values ('o-1', 4200, 'NEW')`;
 
// A stub upstream, which the handler must be pointed at.
const stub = Bun.serve({
port: 8787,
fetch: () => new Response(JSON.stringify({ status: "AUTHORIZED" })),
});
 
test("confirms an order", async () => {
process.env.PAYMENTS_URL = "http://localhost:8787";
const res = await handler(new Request("http://localhost/orders/o-1/confirm", {
method: "POST",
}));
expect(res.status).toBe(200);
});

A stub upstream on a real port, and a real database to seed.

With Keploy~5 minutes
keploy/test-set-0/test-1.yaml
auto-generated
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /orders/o-1/confirm
resp:
status_code: 200
body: '{"id":"o-1","status":"CONFIRMED","total":4200}'
assertions:
noise:
- body.confirmedAt
---
kind: Postgres
spec:
query: select id, total, status from orders where id = $1
rows:
- { id: "o-1", total: 4200, status: "NEW" }
---
kind: Http
spec:
request:
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm
response:
body: '{"status":"AUTHORIZED"}'

Recorded from one real request. Nothing here was typed by hand.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

Bun testing tools, compared

The options a team on Node.js actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your Bun app once, replay it forever

Keploy sits below your Bun process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a Bun service and captures the dependency calls it makes.

Bun logo
Your Bun app
GET/api/v1/orders/{id}200
RecordingKeploy proxyeBPF · userspace
+2 more Bun dependencies
An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Mock coverage

What Keploy mocks for Bun, with zero config

5 of the 6 dependencies a typical Bun service talks to are stubbed from the recording itself — no mock classes, no fixture files, no containers in CI.

Quick start

Your first Bun test suite in under five minutes

Every command below runs against your existing Bun service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    A single binary. It needs a Linux kernel with eBPF support, or Docker on macOS and Windows — and it adds nothing to your project's dependencies.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record your service

    Pass the command you already use to start the app. Keploy runs it and watches every socket it opens.

    keploy record -c "bun run index.ts"
  3. 3Exercise the paths you care about

    Use curl, your frontend, or an existing smoke script. Every request becomes a test case with its Bun calls captured alongside it.

    curl -X POST localhost:3000/orders/o-1/confirm
    curl localhost:3000/orders/o-1
  4. 4Replay in CI

    Replay serves the recorded dependency responses, so the job needs no service containers and no Docker daemon.

    keploy test -c "bun run index.ts" --delay 10

Ready to try it on your own Bun service?

Ecosystem

Works with the rest of your Bun stack

Keploy records at the network layer, so framework and driver choices inside your Bun app do not change how it captures traffic.

FAQ

Bun testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.