[Paper Review] Efficient Mutation Testing via Pre-Trained Language Models
This paper proposes $\mu$ Bert, a mutation testing technique that uses CodeBERT, a pre-trained code language model, to generate natural, developer-like mutants by masking and replacing tokens in code based on contextual predictions. Evaluated on 689 Defects4J bugs, $\mu$ Bert outperforms PiTest by revealing up to 17% more faults, demonstrating higher fault detection capability and cost-efficiency while generating more realistic mutants.
Mutation testing is an established fault-based testing technique. It operates by seeding faults into the programs under test and asking developers to write tests that reveal these faults. These tests have the potential to reveal a large number of faults -- those that couple with the seeded ones -- and thus are deemed important. To this end, mutation testing should seed faults that are both "natural" in a sense easily understood by developers and strong (have high chances to reveal faults). To achieve this we propose using pre-trained generative language models (i.e. CodeBERT) that have the ability to produce developer-like code that operates similarly, but not exactly, as the target code. This means that the models have the ability to seed natural faults, thereby offering opportunities to perform mutation testing. We realise this idea by implementing $μ$BERT, a mutation testing technique that performs mutation testing using CodeBert and empirically evaluated it using 689 faulty program versions. Our results show that the fault revelation ability of $μ$BERT is higher than that of a state-of-the-art mutation testing (PiTest), yielding tests that have up to 17% higher fault detection potential than that of PiTest. Moreover, we observe that $μ$BERT can complement PiTest, being able to detect 47 bugs missed by PiTest, while at the same time, PiTest can find 13 bugs missed by $μ$BERT.
Motivation & Objective
- Address the limitation of traditional mutation testing, which generates unnatural or trivial mutants due to rigid syntactic rules.
- Improve fault detection effectiveness by generating mutants that reflect real programming patterns and conventions.
- Leverage pre-trained language models like CodeBERT to produce contextually relevant, human-like code mutations without requiring grammar rules or fault knowledge.
- Evaluate the approach on real-world bugs to assess its effectiveness and cost-efficiency compared to state-of-the-art tools like PiTest.
- Investigate the impact of additive mutations—especially condition-seeding—on fault detection capability.
Proposed method
- Use CodeBERT’s masked language modeling (MLM) capability to predict plausible token replacements for masked tokens in code, generating contextually appropriate mutants.
- Iterate over each token in program statements, mask it, and generate multiple candidate replacements using CodeBERT’s top predictions.
- Apply filtering to discard non-compilable, duplicate, and syntactically equivalent mutants to ensure valid and diverse mutants.
- Introduce additive mutations by extending control-flow conditions (e.g., adding logical conditions like `||` or `&&`) and re-masking for CodeBERT to complete the expression.
- Combine direct token replacement mutants with condition-seeding mutants to increase mutant diversity and coverage of complex fault patterns.
- Use the generated mutants to guide test suite generation, measuring how many real defects are revealed by tests that kill these mutants.

Experimental results
Research questions
- RQ1Can pre-trained language models generate more natural and effective mutants than traditional syntactic mutation operators?
- RQ2How does $\mu$ Bert's fault detection capability compare to that of PiTest across different configurations (DEFAULT, ALL, RV)?
- RQ3To what extent do additive mutations—specifically condition-seeding—improve fault detection beyond simple token replacement?
- RQ4How cost-efficient is $\mu$ Bert compared to PiTest when measuring fault detection per number of mutants generated?
- RQ5What is the impact of mutant diversity and readability on test effectiveness in real-world bug detection?
Key findings
- On average, $\mu$ Bert reveals 84% of the 689 real bugs in Defects4J, indicating strong fault detection capability.
- $\mu$ Bert outperforms all three PiTest configurations (DEFAULT, ALL, RV), with test suites killing $\mu$ Bert mutants detecting between 5.5% and 33% more real faults.
- Even when comparing the same number of mutants, $\mu$ Bert induces test suites that detect 6% to 16% more faults than PiTest.
- The combination of direct CodeBERT predictions and condition-seeding mutants detects over 9% more bugs than direct predictions alone.
- $\mu$ Bert detects 47 bugs missed by PiTest, while PiTest detects 13 bugs missed by $\mu$ Bert, demonstrating complementary strengths.
- The approach is cost-efficient and requires no grammar rules or fault-specific knowledge, relying solely on learned code distributions from pre-training.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.