---
title: "How well is ClickHouse tested? A detailed view of increasing our own coverage"
description: "ClickHouse, with 2.6 million lines of C++ and over 80 daily pull requests, needed an automated way to assess test coverage. The team implemented Clang source-based coverage instrumentation, running 23 CI shards every three hours to produce a merged report. As of November 2026, the tests cover 91.8% of lines, 81.0% of branches, and 91.8% of functions. A differential coverage check on every PR compares the change against up to seven master baselines and gates merges if line coverage drops more than 0.3 percentage points. The team plans to pursue mutation testing and reduce the noise floor from background threads in future iterations."
---

# How well is ClickHouse tested? A detailed view of increasing our own coverage

[Clickhouse](https://yomu.fyi/company/clickhouse) · Alexey Bakharev and James Cunningham · Nov 25, 2026

**Type:** Explainer

## Summary

ClickHouse, with 2.6 million lines of C++ and over 80 daily pull requests, needed an automated way to assess test coverage. The team implemented Clang source-based coverage instrumentation, running 23 CI shards every three hours to produce a merged report. As of November 2026, the tests cover 91.8% of lines, 81.0% of branches, and 91.8% of functions. A differential coverage check on every PR compares the change against up to seven master baselines and gates merges if line coverage drops more than 0.3 percentage points. The team plans to pursue mutation testing and reduce the noise floor from background threads in future iterations.

## Context

ClickHouse has about 2.6 million lines of C++ code and more than 80 pull requests land in master every day. The team needed an automated way to know which features, components, and settings are covered by tests, because manual tracking is impossible at that pace and scale.

## Approach / What changed

ClickHouse measures test coverage using Clang’s source-based coverage instrumentation (-fprofile-instr-generate -fcoverage-mapping). CI runs 23 test shards (unit, functional, integration) in parallel on a binary built with -DWITH\_COVERAGE=ON, merges the profiles into one tracefile, and renders an HTML report at coverage.clickhouse.com every 3 hours. Per-test coverage is collected via SYSTEM SET COVERAGE TEST and a per-test table. A differential coverage check on every PR compares the PR’s tracefile against up to seven master baselines and gates merges if total line coverage drops more than 0.3 percentage points below master.

## Takeaways

- ClickHouse achieves 91.8% line coverage, 81.0% branch coverage, and 91.8% function coverage using Clang source-based instrumentation across 23 CI shards.
- A differential coverage check on every PR compares the change against up to seven master baselines and gates merges if total line coverage drops more than 0.3 percentage points below master.
- Background threads and parallel execution create a noise floor of about 150 false ‘newly covered’ lines per run even with seven baselines; the team aims to reduce this to a single run.

## FAQ

### How does ClickHouse measure test coverage?

ClickHouse uses Clang's source-based coverage instrumentation (-fprofile-instr-generate -fcoverage-mapping). The binary is built with -DWITH\_COVERAGE=ON, and CI runs 23 test shards in parallel. Each shard produces a .profraw file; llvm-profdata merges them into one .profdata, and llvm-cov produces the report.

### How does the PR coverage gate work?

A differential coverage check runs on every PR. It compares the PR's tracefile against up to seven master baselines. If the total line coverage drops more than 0.3 percentage points below master, the PR fails the gate. The check also reports newly covered and lost baseline lines.

### Why does coverage vary between runs?

Background threads and parallel execution cause a noise floor of a few hundred lines per run. With a single baseline, about 1,300 false 'newly covered' lines appear per run; using seven baselines reduces that to about 150. The team wants one run to be enough in the future.

**Tags:** [CI/CD](https://yomu.fyi/topic/ci-cd), [ClickHouse](https://yomu.fyi/topic/clickhouse), [LLVM](https://yomu.fyi/topic/llvm), [Test Coverage](https://yomu.fyi/topic/test-coverage)

- Source: [Clickhouse](https://clickhouse.com/blog/how-well-is-clickhouse-tested)
- Source URL: https://clickhouse.com/blog/how-well-is-clickhouse-tested
- Ingested by Yomu: 2026-11-25T18:01:08.669Z

[Read original post](https://clickhouse.com/blog/how-well-is-clickhouse-tested)
