NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Predicting Code Coverage without Execution

Michele Tufano, Shubham Chandel, Anisha Agarwal, Neel Sundaresan, Colin B. ClementarXiv 2023 · DOI

Abstract

Researchers from Microsoft have introduced Code Coverage Prediction, a new benchmark task that challenges Large Language Models (LLMs) to predict which lines of code will be executed by a specific test case—without actually running the code. By releasing the COVERAGEEVAL dataset, they demonstrate that while top-tier models like GPT-4 show promise, accurately simulating complex execution logic remains a significant "frontier" for AI code understanding.

Introduction

In software engineering, "code coverage" identifies which parts of a program are exercised by a test suite. Traditionally, calculating this requires instrumenting code, building the project, and executing tests—a resource-intensive process often impossible for isolated code snippets like git diffs or single functions in an IDE.

The authors propose that LLMs capable of predicting coverage via static analysis could provide instantaneous developer feedback. More importantly, this task serves as a rigorous test of execution reasoning. It requires models to mentally simulate program logic—determining if an if statement evaluates to true or false based on specific inputs—rather than just predicting syntactic patterns.

Methods

The task is formalized as a sequence prediction problem. Given a "focal method" (the code under test) and a "test case" (the inputs), the model must output a sequence of symbols for every line:

  • > : The line is executed.
  • ! : The line is missed (not executed).
  • - : The line is unreachable (dead code).

To optimize performance, researchers employed a "Terminal-style" prompt, framing the interaction as a command-line session (e.g., coverage run -m pytest code.py). This encourages the model to "roleplay" as a Python interpreter and coverage tool. Models were evaluated across zero-shot, one-shot, and multi-shot (up to 6 examples) scenarios.

Datasets: COVERAGEEVAL

The COVERAGEEVAL dataset is derived from the HumanEval benchmark, consisting of 164 hand-written Python problems. The authors decomposed multi-assertion tests into 1,160 individual test-method pairs to create a granular dataset requiring reasoning about specific execution paths.

Table 1: Statistics for the COVERAGEEVAL dataset, showing the distribution of problems, solutions, tests, and coverage symbols.

Key Results

Evaluation of four major models—GPT-4, GPT-3.5, Google BARD, and Anthropic Claude—revealed a significant performance gap between state-of-the-art models and their predecessors.

Table 2: Comparative performance of LLMs on the COVERAGEEVAL benchmark across zero-shot, one-shot, and multi-shot settings.
  • GPT-4 Dominance: GPT-4 is the clear leader, achieving a 30.04% Perfect Sequence Match (getting every single line right in a method) in the multi-shot setting.
  • The "Zero-Shot" Cliff: In zero-shot settings, GPT-3.5 and BARD failed to achieve any perfect matches (0%), whereas GPT-4 maintained a respectable 25.75% accuracy.
  • Statement vs. Branch Accuracy: While GPT-4 correctly predicts ~90% of individual statements, its accuracy drops to ~22% for branch-specific statements. This highlights that while the model is "mostly right," it often misses the critical logic gates that define code execution.

Discussion and Insights

  • Execution is Harder than Syntax: LLMs excel at "Statement Correctness" (predicting easy lines like function headers) but struggle significantly with "Branch Correctness" requiring boolean reasoning.
  • The Power of Roleplaying: The terminal-style prompt was the most effective strategy, suggesting LLMs benefit from being placed in a specific "functional context" they likely encountered during training.
  • Pre-training Potential: The authors suggest that "coverage logs" from CI/CD pipelines could be a goldmine for pre-training data, helping future models learn the relationship between inputs and code execution paths.

Limitations and Future Work

COVERAGEEVAL currently focuses on short, self-contained functions from HumanEval. Real-world software involves complex inter-procedural calls that would be much harder to predict. Additionally, the current dataset contains zero instances of truly unreachable code (-), meaning that specific capability remains untested.

Future research directions include integrating these models into IDEs for "Live Coverage" feedback as developers type and using coverage prediction to automatically generate tests that target specific, uncovered lines of code.

Summary updated

BibTeX
@misc{tufano2023predicting,
  author = {Michele Tufano and Shubham Chandel and Anisha Agarwal and Neel Sundaresan and Colin B. Clement},
  title = {{Predicting Code Coverage without Execution}},
  year = {2023},
  eprint = {2307.13383},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.13383},
}
Figure