Keploy logo
ClickHouse logo

Keploy as a ClickHouse testing framework

Keploy mocks ClickHouse by recording its protocol beneath your driver, capturing the exact aggregate rows and column types your queries returned, then replaying them during tests. No cluster runs in CI and no table has to be populated to test an aggregation.

Generate ClickHouse tests free
keploy record -c "./analytics-service"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a ClickHouse team

Captured at the ClickHouse protocol

Keploy records the native or HTTP protocol beneath your driver, so an aggregation replays with the rows the server computed and the column types it declared.

  • Below clickhouse-go, clickhouse-driver, and the JDBC driver
  • Column types and codecs preserved
  • Native and HTTP interfaces
  • Aggregate results captured verbatim
The problem

Why ClickHouse 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 ClickHouse: by hand, with Testcontainers ClickHouse, or with Keploy

A real instance computes the aggregate correctly and needs data inserted to do it. Keploy records the computed result once and replays it with no cluster and no seeding.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for ClickHouse 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
analytics_stub.go
hand-written
// Hand-written stub: the query is never parsed or evaluated.
package analytics
 
type StubStore struct{}
 
func (StubStore) OrdersByState(day time.Time) ([]Bucket, error) {
// The GROUP BY key, the WHERE clause, and the window are
// all invisible here. This answer is just typed out.
return []Bucket{
{State: "NEW", Count: 4127, TotalMinor: 17_340_400},
{State: "CONFIRMED", Count: 9021, TotalMinor: 38_112_900},
}, nil
}

A wrong GROUP BY key or a missing date filter returns these buckets unchanged, so the query under test is the one thing this cannot verify.

Testcontainers ClickHouse1–2 hours
analytics_test.go
tool-assisted
// Testcontainers ClickHouse: real aggregation, real seeding.
package analytics
 
func TestOrdersByState(t *testing.T) {
ch := startClickHouse(t)
mustExec(t, ch, createOrdersTable)
 
// The aggregate is only meaningful with enough rows.
mustInsertRows(t, ch, generateOrders(50_000))
 
buckets, err := New(ch).OrdersByState(day)
if err != nil {
t.Fatal(err)
}
if len(buckets) != 2 {
t.Fatalf("got %d buckets", len(buckets))
}
}

Real aggregation semantics — and fifty thousand inserted rows plus a container boot before a single assertion runs.

With Keploy~5 minutes
mocks.yaml
auto-generated
# Recorded with: keploy record -c './your-service'
# The ClickHouse response, captured at the protocol level.
version: api.keploy.io/v1beta1
kind: ClickHouse
name: mock-2
spec:
request:
query: |
SELECT state, count() AS c, sum(amount_minor) AS total
FROM orders WHERE day = ? GROUP BY state
params: ["2026-09-01"]
response:
columns:
- { name: state, type: LowCardinality(String) }
- { name: c, type: UInt64 }
- { name: total, type: UInt64 }
rows:
- { state: "NEW", c: 4127, total: 17340400 }
- { state: "CONFIRMED", c: 9021, total: 38112900 }

The buckets are what ClickHouse computed over the real dataset, so replay asserts on a genuine aggregate without inserting a single row.

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

Keploy vs the alternatives

ClickHouse testing tools, compared

The options a team on relational databases 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 ClickHouse app once, replay it forever

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

ClickHouse logo
Your ClickHouse app
GET/api/v1/orders/{id}200
RecordingKeploy proxyeBPF · userspace
+2 more ClickHouse clients
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

ClickHouse clients Keploy records, driver by driver

Keploy captures ClickHouse at the wire protocol, so 5 of these 6 clients need no adapter, no test double, and no ClickHouse instance in CI.

Quick start

Your first ClickHouse test suite in under five minutes

Every command below runs against your existing ClickHouse 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 "./analytics-service"
  3. 3Exercise the paths you care about

    Run the app against your development ClickHouse. Every query and the aggregate it computed are captured together.

    curl 'localhost:8080/analytics/orders-by-state?day=2026-09-01'
    curl 'localhost:8080/analytics/revenue?window=7d'
  4. 4Replay in CI

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

    keploy test -c "./analytics-service" --delay 8

Ready to try it on your own ClickHouse service?

Ecosystem

Works with the rest of your ClickHouse stack

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

FAQ

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