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

Contextual Predictive Mutation Testing

Kush Jain, Uri Alon, Alex Groce, Claire Le Goues

Abstract

Mutation testing is a gold standard for software quality, but its massive computational cost makes it impractical for large-scale systems. This paper introduces MutationBERT, a transformer-based model designed to predict whether a test will catch a bug without actually running it. By leveraging contextual encoding and a novel token-level representation of code changes, MutationBERT achieves a 12% improvement in F1 score over previous state-of-the-art methods and reduces the manual verification effort for developers by 33%.

Introduction

In mutation testing, developers inject tiny, synthetic bugs—known as "mutants"—into their code (e.g., changing a > operator to >=) to evaluate the strength of their test suite. If a test fails, the mutant is "killed"; if all tests pass, the mutant is "live," indicating a potential gap in testing coverage. While effective, running every test against every possible mutant is a computational nightmare for large-scale systems, often requiring hundreds of thousands of individual test runs.

Predictive Mutation Testing (PMT) aims to solve this by using machine learning to estimate test outcomes. However, previous models often lacked "context," analyzing mutated lines in isolation or relying on limited metadata like method names. This lack of depth led to high false-positive rates, forcing developers to spend valuable time investigating mutants that the model incorrectly predicted as undetected.

Methodology: MutationBERT

MutationBERT addresses these limitations by leveraging CodeBERT, a transformer model pre-trained on millions of functions, to provide a deep semantic understanding of the code. The approach introduces three key innovations:

  • Contextual Encoding: Unlike prior tools, MutationBERT processes the entire source method containing the mutation alongside the entire test method. This allows the model to reason about how a change on one line might propagate through the logic to affect an assertion elsewhere.
  • Token-Level Diff: To represent mutations efficiently, the authors developed a compact representation using special tokens. For example, a change from != to > is encoded as: if (h <BEFORE> != <AFTER> > <ENDDIFF> LAST_HOUR). This enables the model to see the exact modification within its surrounding syntactic structure.
  • Threshold Aggregation: To determine if a mutant is detected by a full test suite, the model employs a tuned confidence threshold. The researchers found that if the model is at least 25% confident that any single test in the suite catches the mutant, it is likely detected. This tuning balances precision and recall for practical software engineering workflows.

Experimental Setup

The researchers evaluated MutationBERT using the Defects4J 2.0 dataset, a standard benchmark featuring six large-scale Java projects, including jfreechart, gson, and commons-lang. The study analyzed two primary scenarios:

  1. Same Project: Training and testing on different versions of the same software.
  2. Cross Project: Training on one project and testing on a completely different codebase to evaluate generalization.

MutationBERT's performance was compared directly against Seshat, the previous state-of-the-art model in predictive mutation testing.

Key Results and Insights

MutationBERT demonstrated significant improvements across all primary metrics:

  • Superior Accuracy: The model achieved an F1 score of 0.79 at the test-suite level, compared to 0.67 for Seshat.
  • Cross-Project Generalization: When tested on entirely new codebases, MutationBERT maintained a significant lead, achieving an F1 score of 0.58 versus the baseline's 0.30, proving its ability to learn general programming patterns rather than just project-specific quirks.
  • Handling Hard-to-Detect Mutants: The model is notably better at identifying "non-trivial" mutants—those caught by only a tiny fraction of tests. In these difficult cases, MutationBERT showed a 30% improvement in accuracy over previous methods.
  • Developer Efficiency: By providing more precise predictions and fewer false alarms, MutationBERT reduces the human labor involved in manual mutant verification by approximately one-third.

Limitations and Future Work

While MutationBERT represents a significant leap forward, it has specific operational requirements. The model is optimized for GPUs; on a standard CPU, its throughput drops from 29 pairs per second to 12, which may impact integration into standard CI/CD pipelines lacking specialized hardware. Additionally, the model has a context window limit of 1024 tokens. In approximately 14.6% of test cases, methods were too long and had to be truncated, potentially losing relevant information.

Future research directions include utilizing larger models (such as Codex or other Large Language Models) with expanded context windows to eliminate truncation issues and further improve the understanding of complex test helper methods.

Summary updated

BibTeX
@inproceedings{jain2023contextual,
  author = {Kush Jain and Uri Alon and Alex Groce and Claire Le Goues},
  title = {{Contextual Predictive Mutation Testing}},
  booktitle = {ESEC/SIGSOFT FSE},
  year = {2023},
  doi = {10.1145/3611643.3616289},
}
Figure