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

µBert: Mutation Testing using Pre-Trained Language Models

Renzo Degiovanni, Mike Papadakis · DOI

Introduction

Mutation testing is a rigorous technique for evaluating the quality of software test suites. By injecting small, intentional faults (mutants) into a program, developers can determine if their tests are capable of detecting errors. If a test suite fails to "kill" a mutant, it indicates a gap in the testing coverage. However, traditional mutation testing often suffers from the "naturalness" problem: the generated mutants frequently represent code patterns that no human developer would ever write, leading to wasted effort and reduced developer trust. μBERT addresses this by leveraging the power of pre-trained language models to generate more realistic software bugs.

The Challenge of Unnatural Mutants

Standard tools like PiTest rely on predefined syntactic mutation operators—such as swapping a > for a < or changing a + to a -. While effective at a basic level, these operators are context-blind. They might create infinite loops or trivial null pointer exceptions in code paths where such errors are improbable. This lack of realism makes it difficult to correlate mutation scores with real-world bug-finding capabilities. The authors of μBERT argue that for mutation testing to be truly effective, the mutants must be "natural"—meaning they should resemble plausible human errors.

Methodology: μBERT Architecture

The core innovation of μBERT is replacing manual mutation operators with a Masked Language Model (MLM)—specifically CodeBERT, which was trained on over 6 million programs. This allows the tool to be context-aware rather than context-free.

The μBERT workflow follows four primary stages:

  1. Parsing: The tool identifies candidate expressions for mutation within the Java source code, such as method calls, assignments, and logical expressions.
  2. Masking: Instead of applying a hard-coded rule, μBERT masks a single token in the expression (e.g., if (a > b) becomes if (a <mask> b)).
  3. Prediction: The masked sequence is processed by CodeBERT. Because the model understands the surrounding code context (up to 512 tokens), it predicts the top five most likely tokens to replace the mask.
  4. Generation and Filtering: Mutants are generated from these predictions. Any mutant that fails to compile or is identical to the original code is automatically discarded.

Unlike traditional tools that might blindly change every operator, μBERT might replace a variable name with another relevant variable in that specific context or change a method call to a semantically similar one (e.g., changing list.add(c) to list.push(c)).

Experimental Evaluation

The authors evaluated μBERT against the industry-standard tool PiTest using two main benchmarks:

  • Defects4J: A dataset of real-world Java bugs. The study focused on 40 bugs across the Cli, Collections, and Csv projects.
  • SpecFuzzer Dataset: Used to evaluate μBERT’s utility in assertion inference, involving 41 manually written assertions across methods like StackAr.pop.

Key Results

Superior Cost-Effectiveness

The most significant finding is that μBERT is up to two times (100%) more cost-effective than PiTest. It generates far fewer mutants, but the mutants it produces are of higher quality. This means developers spend less time analyzing "junk" mutants while achieving the same or better bug-finding power.

Better Fault Detection

In the head-to-head comparison on 40 real-world bugs, μBERT-guided test suites found 27 bugs, while PiTest found 26. Notably, μBERT identified three bugs that PiTest missed entirely, demonstrating its ability to uncover subtle errors that escape rigid syntactic rules.

Improving Specifications

In the assertion inference task, μBERT helped preserve 3 out of 6 valid assertions that traditional mutation testing would have mistakenly discarded, showing its value in refining software specifications.

Conclusion and Future Work

μBERT demonstrates that "naturalness" is a powerful proxy for mutant quality. By replacing manual, context-free rules with a generative model, the tool creates mutants that better mimic human error. While the current study is a preliminary evaluation on 40 bugs, it suggests a promising path forward for the field. Future work will focus on scaling the tool to the full Defects4J dataset (800+ bugs) and exploring newer models like GraphCodeBERT to further refine the mutation process.

Summary updated

BibTeX
@misc{degiovanni2022bert,
  author = {Renzo Degiovanni and Mike Papadakis},
  title = {{µBert: Mutation Testing using Pre-Trained Language Models}},
  year = {2022},
  eprint = {2203.03289},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2203.03289},
}
Figure