TL;DR
This paper presents a comprehensive empirical study on using Large Language Models (LLMs) for mutation testing, finding that LLMs significantly outperform traditional methods in generating effective and diverse mutants that better mimic real bugs. While LLMs offer a substantial improvement in fault detection, they also introduce challenges like a higher rate of non-compilable mutants.
What Problem Does This Paper Address?
Mutation testing is a crucial technique for evaluating the effectiveness of software tests. It involves introducing small syntactic changes (mutants) into the source code and checking if existing tests can detect these changes. The goal is to generate "high-utility" mutants that closely resemble real-world bugs. However, traditional methods for generating these mutants, whether rule-based or based on smaller learning models, often struggle with producing diverse mutants, ensuring they are behaviorally similar to real faults, and avoiding redundant or non-compilable mutants. This paper addresses the gap in understanding how Large Language Models (LLMs), which have shown remarkable capabilities in code-related tasks, perform in the context of mutation testing, and whether they can overcome the limitations of existing approaches.
Methods
The authors conducted a comprehensive empirical study comparing traditional mutation testing approaches with LLM-based methods. They evaluated several LLM-based approaches, including existing ones like BugFarm and LLMorpheus, and introduced their own novel prompt template called "LLMut." This LLMut approach was tested with various LLMs, including GPT-40, GPT-3.5-Turbo, DeepSeek-V3-671b, DeepSeek-Coder-V2-236b, StarChat-β-16b, and CodeLlama-Instruct-13b. The study also investigated the impact of different prompt engineering strategies, context lengths, and few-shot examples on LLM performance. Key metrics used for evaluation included Real Bug Detection Rate, Average Ochiai Coefficient, Coupling Rate, Compilability Rate, Duplicate Mutant Rate, and Equivalent Mutant Rate.
Datasets
The study utilized two primary Java bug datasets:
- Defects4J 2.0: A widely used benchmark containing 605 bugs from 12 open-source projects.
- ConDefects: A dataset designed to mitigate potential data leakage concerns, comprising 246 Java bugs collected from recent programming contest tasks.
Additionally, the QuixBugs dataset was used for sampling few-shot examples for prompt engineering, as it is commonly used in testing and debugging research.
Key Insights and Ideas
- LLMs are significantly better at mimicking real bugs: The core finding is that LLMs generate mutants that are more behaviorally aligned with actual software defects, leading to a substantial increase in fault detection.
- Diversity is a key LLM advantage: LLMs introduce a much wider variety of syntactic changes (AST node types) compared to traditional methods, suggesting a broader exploration of the code space.
- Prompt engineering matters: The way prompts are designed significantly impacts LLM performance, with the "LLMut" approach showing strong results. Including contextual information like the whole Java method or focal method code proved more effective than just the target code element.
- Non-compilable mutants are a major LLM challenge: While LLMs excel in effectiveness, they produce a considerably higher rate of mutants that fail to compile. "Usage of Unknown Methods" and "Code Structural Destruction" were identified as the most frequent error types.
- LLMs can guide test suite improvement: Surviving mutants generated by LLMs are more likely to be "not covered" or "not injected" by existing tests, providing valuable direction for augmenting test suites.
Key Results
- Fault Detection: LLM-based approaches achieved a 1.75x improvement in real bug detection rate, reaching an average of 76.47% compared to 44.15% for rule-based techniques. LLMut (DS-671b) achieved the highest detection rate at 91.1%.
- Semantic Similarity: LLMut (DS-671b) achieved the highest Average Ochiai Coefficient at 59.8%, indicating mutants closely aligned with real bugs.
- Compilability: Traditional rule-based approaches like PIT and Major achieved near-perfect compilability rates (100% and 97.60%, respectively). LLM-based approaches showed significant variation, with LLMut (DS-671b) and BugFarm (DS-671b) achieving the highest at around 77.6%.
- Duplicate Mutants: Rule-based approaches achieved 0% duplicate mutant rates, while LLM-based approaches ranged from 3.1% to 12.8%.
- Equivalent Mutants: Traditional approaches had slightly lower equivalent mutant rates (e.g., 1.0% for PIT, 2.1% for Major) compared to LLM-based approaches (ranging from 3.1% to 10.6%).
- Efficiency: Traditional approaches were significantly faster, with PIT generating mutants in 0.02 seconds on average, while the best LLM approach took 1.31 seconds.
Limitations and Future Work
- Non-compilable Mutants: The high rate of non-compilable mutants remains a significant challenge for LLMs, limiting their practical application. Future work should focus on integrating LLMs with program analysis and repair techniques to refine mutant generation.
- Limited Scope: The study was primarily conducted on Java. Future research should explore the cross-language generalization capabilities of LLMs for mutation testing in languages like C/C++, Python, and JavaScript.
- Dynamic Indicators: The study did not investigate advanced dynamic indicators like subsuming mutants, which could provide deeper insights into mutant effectiveness.
- Fixed Few-Shot Examples: The use of fixed few-shot examples might introduce biases. Future work could explore more dynamic or adaptive few-shot learning strategies.
- Operator Constraints: The study did not constrain LLMs to the same operator set as rule-based approaches, leaving open the question of how LLMs would perform under such constraints.
- Downstream Tasks: Exploring the application of LLM-generated mutants in downstream tasks like test case prioritization and fault localization is a promising direction.
Summary updated