Keploy logo
Phoenix logo

Keploy as a Phoenix testing framework

Keploy tests Phoenix services by recording real HTTP and database traffic from a running process, then replaying it as assertions. There is no test context to assemble and no framework wiring to change, because capture happens below the framework at the socket.

Generate Phoenix tests free
keploy record -c "mix phx.server"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a Phoenix team

Any Phoenix service, unchanged

Keploy runs the Phoenix process unchanged. Routing, middleware and serialisation all execute on every recorded request, because capture is at the socket rather than inside the framework.

  • Any Phoenix version
  • Middleware runs unchanged
  • Routing and serialisation real
  • No plugin or adapter
The problem

Why Phoenix 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 Phoenix: by hand, with ExUnit + Phoenix.ConnTest, or with Keploy

ExUnit + Phoenix.ConnTest 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 Phoenix 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.exs
hand-written
defmodule AppWeb.OrderControllerTest do
use AppWeb.ConnCase, async: true
import Mox
 
setup :verify_on_exit!
 
test "confirms an order", %{conn: conn} do
# A behaviour-backed mock: no Postgrex, no rows.
expect(MockRepo, :find_order, fn "o-1" ->
{:ok, %Order{id: "o-1", total: 4200, status: "NEW"}}
end)
 
expect(MockPayments, :authorize, fn _ ->
{:ok, %{"status" => "AUTHORIZED"}}
end)
 
conn = post(conn, ~p"/orders/o-1/confirm")
 
assert json_response(conn, 200)["status"] == "CONFIRMED"
end
end

The Mox mock satisfies a behaviour, so Ecto never runs.

ExUnit + Phoenix.ConnTest1–2 hours
orders_bypass_test.exs
tool-assisted
defmodule AppWeb.OrderControllerBypassTest do
use AppWeb.ConnCase, async: false
 
setup do
bypass = Bypass.open()
 
# A real Cowboy endpoint, with a plug body you write.
Bypass.expect(bypass, "POST", "/v1/payment_intents/tok_123/confirm", fn conn ->
Plug.Conn.resp(conn, 200, ~s({"status":"AUTHORIZED"}))
end)
 
{:ok, bypass: bypass}
end
 
# Ecto's sandbox still needs a real database in the job.
test "confirms an order", %{conn: conn} do
conn = post(conn, ~p"/orders/o-1/confirm")
assert json_response(conn, 200)
end
end

ExUnit + Phoenix.ConnTest gives a real local endpoint. The database is still real too.

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

Phoenix testing tools, compared

The options a team on the BEAM 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 Phoenix app once, replay it forever

Keploy sits below your Phoenix 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 Phoenix service and captures the dependency calls it makes.

Phoenix logo
Your Phoenix app
GET/api/v1/orders/{id}200
RecordingKeploy proxyeBPF · userspace
Outbound HTTP
Outbound HTTPEvery outbound HTTP call
+2 more Phoenix 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 Phoenix, with zero config

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

Quick start

Your first Phoenix test suite in under five minutes

Every command below runs against your existing Phoenix 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 "mix phx.server"
  3. 3Exercise the paths you care about

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

    curl -X POST localhost:4000/orders/o-1/confirm
    curl localhost:4000/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 "mix phx.server" --delay 15

Ready to try it on your own Phoenix service?

Ecosystem

Works with the rest of your Phoenix stack

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

FAQ

Phoenix 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.