Causal Inference for the Effect of Code Coverage on Bug Introduction

Lukas Schulte, Gordon Fraser, Steffen Herbold

Abstract

Context: Code coverage is widely used as a software quality assurance measure. However, its effect, and specifically the advisable dose, are disputed in both the research and engineering communities. Prior work reports only correlational associations, leaving results vulnerable to confounding factors. Objective: We aim to quantify the causal effect of code coverage (exposure) on bug introduction (outcome) in the context of mature JavaScript and TypeScript open source projects, addressing both the overall effect and its variance across coverage levels. Method: We construct a causal directed acyclic graph to identify confounders within the software engineering process, modeling key variables from the source code, issue- and review systems, and continuous integration. Using generalized propensity score adjustment, we will apply doubly robust regression-based causal inference for continuous exposure to a novel dataset of bug-introducing and non-bug-introducing changes. We estimate the average treatment effect and dose-response relationship to examine potential non-linear patterns within the projects of our dataset.

Introduction: Beyond Correlation

In software engineering, code coverage—the percentage of code executed by tests—is a ubiquitous metric for quality. However, the industry remains divided on its actual value. Does high coverage prevent bugs, or is it merely a "vanity metric" that correlates with simple, well-written code?

Most existing research only demonstrates correlation: projects with high coverage tend to have fewer bugs. However, correlation is not causation. A confounding factor, such as developer experience, might drive both: a senior developer writes better code (fewer bugs) and better tests (higher coverage). In this scenario, the coverage itself didn't prevent the bug—the developer's skill did. This study employs causal inference to untangle these factors and measure the direct impact of coverage on bug introduction.

Methodology: The Causal Framework

The authors employ a "doubly robust" causal inference pipeline to analyze observational data from software repositories.

Causal Directed Acyclic Graphs (DAGs)

The researchers constructed a formal map of the software development process to identify "backdoor paths." These are confounders—like change complexity, developer experience, and programming language (JS vs. TS)—that must be controlled to isolate the effect of coverage.

The Causal Directed Acyclic Graph (DAG) used to identify and control for confounding variables in the software development process.

Statistical Adjustments

Since code coverage is a continuous variable (0% to 100%), the authors use Generalized Propensity Score (GPS) adjustment to balance the dataset. This simulates a controlled experiment by weighting commits so that those with high and low coverage are comparable across all other variables. This is combined with Doubly Robust Regression, a method that provides a valid causal estimate even if the model of exposure or the model of outcome is slightly misspecified.

Data and Experimental Setup

The study introduces a novel longitudinal dataset derived from 20 mature open-source projects randomly sampled from over 500 candidates on GitHub.

Tracking Commits and Bugs

To identify which commits introduced bugs, the authors use an improved version of the SZZ algorithm, which traces bug-fixing commits back to the original lines of code. The study specifically looks at Feature Branch Commits (FBC) and their integration into the main branch via Merge Commits (MC).

A diagram of the Git workflow showing Feature Branch Commits (FBC) merging into the main branch (MC), the primary units of analysis.

The WayPack Machine

A new tool, the WayPack Machine, was developed for the temporal reconstruction of npm/yarn dependency contexts. This ensures that historical commits can be built and tested today to extract accurate historical coverage data, overcoming the common issue of "bit rot" in old dependencies.

Expected Insights: The Dose-Response Curve

Instead of looking for a single "magic number" for coverage, the study seeks a Causal Dose-Response Function. This visualization shows how bug risk fluctuates across the full 0–100% coverage spectrum, helping identify non-linear patterns such as:

  • Diminishing Returns: Where increasing coverage (e.g., from 80% to 90%) provides negligible benefit.
  • Thresholds: Where coverage only starts significantly reducing bugs after reaching a certain percentage.

Limitations

Causal models rely on the researchers' assumptions regarding variable interactions; a missing link in the DAG could lead to biased results. Additionally, the SZZ algorithm is known to be "noisy" and may occasionally misidentify bug-introducing commits. Finally, while the findings will be robust for mature open-source JS/TS projects, the dynamics might differ in proprietary software or different programming ecosystems.

Summary updated

BibTeX
@misc{schulte2026causal,
  author = {Lukas Schulte and Gordon Fraser and Steffen Herbold},
  title = {{Causal Inference for the Effect of Code Coverage on Bug Introduction}},
  year = {2026},
  eprint = {2602.03585},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.03585},
}
Figure