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

DeepMutation: A Neural Mutation Tool

Michele Tufano, Jason Kimko, Shiya Wang, Cody Watson, Gabriele Bavota, Massimiliano Di Penta, Denys PoshyvanykarXiv 2020 · DOI

TL;DR

DeepMutation is the first automated toolchain that uses Neural Machine Translation (NMT) to generate software mutants that actually look like real-world bugs. By training a deep learning model on nearly 800,000 historical bug fixes, the tool can automatically inject representative faults into Java projects to rigorously evaluate the effectiveness of test suites.

What Problem Does This Paper Address?

Mutation testing is a powerful technique for checking if your tests are actually any good. It works by "mutating" your source code (e.g., changing a > to a >=) and seeing if your tests catch the change. If the tests pass despite the mutation, you have a "surviving mutant," indicating a gap in your test suite.

However, traditional mutation testing has a major flaw: the mutations are often simplistic and don't resemble the complex, messy bugs that developers actually write. Manually designing better mutation operators is incredibly labor-intensive. DeepMutation addresses this by automating the creation of "representative" mutants—faults that mimic the patterns found in hundreds of thousands of real-world bug fixes.

Methods

The authors built a complete pipeline to move from raw source code to a tested, mutated project. The architecture consists of five main stages:

  1. Extractor: Uses the Spoon library to analyze a Java project and extract individual methods for mutation.
  2. Abstractor: To keep the neural network's vocabulary manageable, this stage replaces specific variable names and literals with "Typified IDs" (like VAR_1 or INT_0). It keeps Java keywords and common "idioms" (like .size() or 0) intact to preserve semantic meaning.
  3. Mutator (The Core): This is a Recurrent Neural Network (RNN) Encoder-Decoder with an attention mechanism. It was trained on a massive corpus of bug fixes to perform a "reverse translation": taking a correct method and "translating" it into a buggy version. It uses Beam Search to generate multiple candidate mutations for a single piece of code.
  4. Translator: This stage maps the abstract "Typified IDs" back to the original variable names, turning the abstract mutant back into valid Java source code.
  5. Compiler & Tester: Finally, the tool automatically attempts to compile the mutated project and run the existing test suite to see if the new "bug" is detected.
The DeepMutation pipeline: from raw system code to mutated, tested projects.

Datasets

The NMT model was pre-trained on a massive dataset of ~787,000 bug-fixing changes mined from thousands of public GitHub repositories.

For the evaluation presented in this paper, the authors tested the tool on four well-known Java projects from the Defects4J benchmark: Chart, Lang, Math, and Time. Crucially, they did not fine-tune the model on these projects, testing its ability to "transfer" its knowledge of bugs to entirely new codebases.

Key Insights and Ideas

  • Learning from History: Instead of humans guessing what bugs look like, DeepMutation lets the data speak. By training on nearly a million real fixes, it learns the subtle patterns of human error.
  • Abstraction is Essential: A neural network can't learn every possible variable name in existence. By abstracting code into types and roles (the "Typified IDs"), the authors allowed the model to focus on the structure of the logic and the nature of the changes rather than specific naming conventions.
  • Context Matters: The use of an attention mechanism allows the model to "look back" at specific parts of the input method when deciding how to mutate it, ensuring the generated bug is contextually relevant.

Key Results

The preliminary evaluation showed that DeepMutation is both scalable and effective at generating plausible code:

  • High Translation Success: The Translator successfully converted abstract mutants back into concrete source code in 82% to 97% of cases across the four test projects.
  • Compilability: Between 35% and 67% of the resulting mutated projects compiled successfully. While this might seem low, it is a significant achievement for a deep-learning-based code generation tool, as even small syntax errors can break a build.
  • Efficiency: The tool is fast enough for real-world use. Excluding the time taken by the Java compiler itself, DeepMutation can extract, mutate, and translate thousands of methods in just 5 to 12 minutes.
Table 1: Preliminary Evaluation Results
Table 2: Timing Performances

Limitations and Future Work

The primary limitation is the compilability rate. Because the model generates code token-by-token, it can sometimes produce sequences that are syntactically incorrect or violate Java's typing rules.

The authors plan to address this by integrating the compiler directly into the Beam Search process. If the most likely mutant doesn't compile, the tool could automatically try the second or third most likely candidate until it finds one that works. They also plan to expand the tool's scope beyond the method level to handle larger or smaller code granularities.

Summary updated

BibTeX
@misc{tufano2020deepmutation,
  author = {Michele Tufano and Jason Kimko and Shiya Wang and Cody Watson and Gabriele Bavota and Massimiliano Di Penta and Denys Poshyvanyk},
  title = {{DeepMutation: A Neural Mutation Tool}},
  year = {2020},
  eprint = {2002.04760},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2002.04760},
}
Figure