Editor’s introduction
The study evaluates AdverTest, a framework using two AI agents to generate software tests. One agent creates test cases, while the other generates mutants to challenge them. The system iteratively refines tests to detect vulnerabilities, improving both coverage and fault detection. Results from the Defects4J dataset show AdverTest outperforms existing LLM-based methods and EvoSuite in detecting faults and achieving coverage.
Introduction
Unit testing is a critical and resource-intensive phase in the software development lifecycle, forming the foundation for building robust software. However, writing high-quality unit tests remains a tedious and time-consuming task for developers. The goal of automated test case generation is to alleviate this burden by generating high-quality test cases that can cover diverse program behaviors and detect faults efficiently. Throughout this paper, we use robustness to mean a test suite’s ability to expose diverse fault behaviors, captured by our primary metric, the fault detection rate (FDR).
There have been various approaches for automated test case generation, such as random testing, symbolic execution, property-based testing, and search-based software testing (SBST). While these traditional methods can achieve substantial code coverage, the resulting tests are often less readable and harder to maintain. As a result, they can increase developer effort for debugging and comprehension, as well as generate too few assertions for effective fault detection.
In recent years, the growing capabilities of LLMs to generate and understand human-readable code have provided new opportunities for automated test case generation. For instance, UTGen integrates LLMs into the SBST process, yielding tests that are both effective and understandable. Similarly, CodaMosa addresses the fitness plateau problem in search-based testing by incorporating LLMs into the test generation process. As a result, CodaMosa outperforms its baseline methods, such as Pynguin and Codex, in terms of code coverage. Additionally, HITS demonstrates LLMs’ ability to generate high-coverage tests for complex methods by generating tests slice by slice.
Automated Test Case Generation
Automated unit test generation has progressed from early heuristic approaches to advanced AI-driven methods. Traditional techniques such as feedback-directed random testing (e.g., Randoop ) and search-based tools (e.g., EvoSuite ) achieve high code coverage but often produce tests that are hard to maintain or understand. To improve quality, researchers reframed test generation as a code synthesis task solvable with machine learning. For example, Tufano et al. trained a transformer model on code–test pairs (AthenaTest) to automatically generate JUnit tests for a given method. Subsequent neural approaches introduced refinements: A3Test added assertion knowledge and naming consistency checks to improve correctness, and other systems (e.g., ConTest, TeCo, CAT-LM) enhanced semantic understanding and output readability.
The emergence of LLMs has further accelerated progress. Empirical studies showed that modern code-generating LLMs (e.g., Codex or GPT-3.5) can produce unit tests in a human-like style, but they struggled to achieve high coverage on complex code and often introduced “test smells” (redundant or trivial tests). To better harness LLMs, researchers have integrated these models with program analysis and feedback. For instance, tools like TestPilot and ChatUniTest pair LLM-based generation with static analysis and verification loops to produce valid, high-coverage tests. Hybrid strategies have also emerged: for example, CODAMOSA invokes an LLM when a search-based test generator hits a coverage plateau, generating tests for hard-to-cover functionality. Additionally, some frameworks use an iterative loop where an LLM refines its tests based on feedback from prior test runs (e.g., coverage gaps or errors). CoverUp uses coverage rate as a feedback and achieves a higher coverage than CODAMOSA on most modules. These LLM-driven techniques are yielding test suites that are not only more readable but also more effective at finding bugs, with substantial gains in coverage and fault detection reported in both research and industry.
Unlike prior LLM-based generators that use one-way feedback (e.g., compiler errors or coverage gaps) to refine tests, AdverTest introduces a second LLM that creates context-aware mutants and engages the test generator in an adversarial loop. This bidirectional loop, guided by mutation-score and coverage feedback, pushes each agent to close the other’s blind spots and yields more robust fault detection.
Mutation Testing
Mutation testing evaluates a test suite’s rigor by seeding artificial faults (mutants) into the program and checking if the tests detect them. In the classical approach, developers apply simple code modifications (mutation operators) to produce mutants, then run the suite on each mutant; the fraction of mutants causing test failures (the mutation score) indicates the suite’s fault-detection effectiveness.
MT has long been used in traditional automated test generation workflows; for example, EvoSuite applies mutation testing to synthesize assertions. In LLM-based methods, the effects of MT have not yet been thoroughly explored. MuTAP was the first to explore the generation of LLM-based test cases with mutation testing. MuTAP integrates surviving mutants into LLM prompts to improve fault detection, but was evaluated solely on HumanEval and Refactory, a dataset of student submitted buggy programs, not on industrial scale projects. Despite this narrow scope, MuTAP achieved notable gains in both mutation score and bug detection rate. Recently, Harman et al. utilized LLM-generated mutants in test generation, but it is not adversarial and evolutionary. Barboni et al. employ an ML model to evaluate the usefulness of each surviving mutant, then prompt them to LLM to generate test cases for smart contracts.
Studies have shown that LLM-generated mutants are more diverse and effective at revealing bugs than those from conventional tools: Wang et al. report that GPT-4 mutants improved real fault detection by nearly 30% over the best rule-based approach in a benchmark evaluation. Similarly, LLM-created mutants often mimic real vulnerabilities, breaking the same test cases as the actual faults.
Initial Mutant Generation
To further promote mutation diversity and correctness, we adopt prior research on prompt-based mutation. Specifically, we enforce a single-line modification constraint. This design choice is grounded in the two fundamental hypotheses of mutation testing: the Competent Programmer Hypothesis and the Coupling Effect. The latter asserts that “test data that distinguishes all programs differing from a correct one by only simple errors is so sensitive that it also distinguishes more complex errors”. By restricting mutants to single-line changes, we focus on these relatively simple errors, ensuring the generated test suite is sensitive enough to detect complex faults while minimizing the generation of uncompilable code common in unconstrained LLM generation.
Datasets
We evaluate AdverTest on Defects4J and GrowingBugs, two datasets that provide authentic and reproducible defects in industrial-scale Java code bases. With a total of 20 different projects, 247 different bugs, 727 methods under test. This scale significantly surpasses the evaluations of previous work, such as HITS (120 methods) and ChatUniTest (264 methods).
Defects4J. Defects4J is a widely adopted benchmark of real, reproducible faults in open source Java projects. In version 2.1.0, it comprises 835 more bugs drawn from 17 different and high quality projects, each paired with a corresponding fixed version and a comprehensive test suite. Each defect entry includes metadata such as affected files, trigger tests, and developer patches, allowing repeatable fault detection and repair experiments. In this experiment, we used 200 randomly sampled defects from all 17 projects. We also leverage Defects4J framework throughout our experiment and evaluation.
GrowingBugs. GrowingBugs is an extensible repository of real faults in open source Java projects built on top of the Defects4J infrastructure. GrowingBugs automatically filters out non-functional changes from commit histories using the BugBuilder tool, enabling continuous expansion of the dataset without human intervention. Previous studies have shown that patches extracted by the BugBuilder preserve the naturalness of real bugs and support robust empirical evaluations of testing and repair techniques. To mitigate potential data leakage, we specifically selected all 3 projects that were introduced into the GrowingBugs benchmark after the knowledge cutoff date of the LLM we use for that experiment: commons-dbcp (Dbcp), commons-beanutils (Beanutils), and commons-fileupload (Fileupload). This subset comprises a total of 47 bugs and 89 methods under test. We caution that “recently added to GrowingBugs” applies to the benchmark inclusion date, not necessarily to the individual bug introduction dates: some defects in these projects pre-date the LLM training cutoff and could in principle have been observed during pre-training. To further address this residual leakage concern, Section 5.4 reports an additional generalization study on 12 Python bugs drawn from real GitHub issues post-dating the model cutoff.
Baselines
We compare AdverTest against four baselines, two traditional and two LLM-driven: Randoop, a feedback-directed random Java test generator; EvoSuite, a search-based tool that evolves JUnit suites toward high line and branch coverage; ChatUniTest, an LLM-driven generator that supplies the focal method plus rule-extracted context and uses error-driven test repair (its coverage drops on complex methods ); and HITS, an LLM-driven generator that decomposes complex methods into semantically coherent slices and generates tests per slice, achieving the highest LLM-baseline coverage on complex methods. We configure EvoSuite and Randoop with a 500 seconds per-bug budget, comparable to AdverTest’s runtime on Defects4J.
Both LLM baselines use DeepSeek-v3.2 and GPT-OSS-120B (we restrict GrowingBugs to DeepSeek-v3, whose cutoff predates the dataset ). We adapt both for Defects4J: prompts target JUnit 4 instead of JUnit 5, and tests are executed with the Defects4J command. Other LLM- and mutation-guided systems are not directly comparable in the context of industrial Java projects. MuTAP targets Python and is evaluated only on student-program benchmarks; Meta’s mutation-guided system is closed-source; and Alchemist focuses on Solidity smart contracts.
Fault Detection Capability
AdverTest consistently achieves high fault detection rates across all datasets. On the Defects4J dataset, AdverTest (using DeepSeek V3.2) attains an FDR of 66.63%. This represents a relative improvement of approximately 8.6% over the state-of-the-art LLM-based method, HITS (61.38%), and a substantial 50.20% improvement over the traditional search-based tool, EvoSuite (44.36%). A similar trend is observed on the GrowingBugs dataset, where AdverTest achieves 65.96% FDR compared to 61.70% for HITS and 40.43% for EvoSuite. This result is particularly significant, as GrowingBugs contains defects introduced more recently, serving as a rigorous test for data leakage and overfitting.
Coverage
In terms of coverage, EvoSuite achieves the highest line and branch coverage on Defects4J under the matched 500 s budget, with AdverTest a close second on both metrics. This higher coverage, however, does not translate into higher fault detection: EvoSuite’s FDR (44.36%) still trails AdverTest’s 66.63% by a wide margin. EvoSuite primarily optimizes for code execution (coverage and weak mutation), often generating tests that reach a faulty line without propagating the error to an observable output. In contrast, AdverTest integrates strong mutation directly into the loop: surviving mutants explicitly guide the LLM to generate tests that distinguish the mutant’s behavior from the original code, ensuring the generated tests not only execute the code but also rigorously expose semantic faults.
RQ2: Ablation Study
Replacing mutation feedback with coverage-only signals (w/ Cov-only) drops FDR to 34.00%, which is lower than w/o Mut’s 40.00% despite slightly higher coverage (80.33% line). This suggests that surviving-mutant feedback carries information beyond what coverage signals alone provide. Substituting the LLM mutator with the rule-based MAJOR tool (w/ MAJOR) loses 8 pp FDR (from 54.00% to 46.00%) while coverage remains nearly intact (85.71% line), suggesting that the LLM mutator’s contribution stems more from qualitative mutant diversity than from reaching new lines.
RQ3: Effect of Iterative Rounds
Line Coverage (Purple): Coverage shows a steady but modest increase, rising from 88.0% to 94.8% (+7.7%). The high initial starting point suggests that modern LLMs are inherently proficient in achieving structural coverage. Consequently, the marginal gains diminish in later rounds as the code becomes saturated.
Fault Detection Rate (Orange): The most substantial improvement is observed in the FDR, which surges from 35.3% to 67.6% (+91.7%). Notably, while coverage increases moderately, FDR continues to rise significantly in later iterations (e.g., the jump at Round 3 and 7). This confirms that the mutation guided adversarial loop successfully directs the agents toward corner cases and logical faults that coverage metrics overlook and generate more robust test cases.
RQ4: Generalization Beyond Defects4J
To verify that the adversarial loop transfers beyond Java and Defects4J, we re-implemented AdverTest for Python and evaluated it on the SWE-Rebench benchmark, which is continuously updated from live GitHub issues. We used 12 instances from the SWE-Rebench 2026-02 leaderboard, all of which post-date the LLM training cutoff, providing a stronger data-leakage control than relying on benchmark inclusion dates alone (cf. Section 6).
Leakage Controls
Throughout the loop, the LLM receives only the source code of the fixed target function, the file path, and module-level context. It never sees the GitHub issue description, the developer patch, the developer-written tests, the hint text, or the FAIL_TO_PASS oracle from SWE-Rebench. The only bug-specific information used by the pipeline is the function-level scope (which method the patch touches), which is the same level of supervision AdverTest uses on Defects4J. The 91.7% FDR is therefore obtained on bugs whose patches were not in the model’s training data and whose oracles the pipeline does not see.
Threats to Validity
Construct Validity. We measure effectiveness using fault detection rate and coverage metrics (line and branch). Fault detection rate relies on the accuracy of defect annotations in Defects4J and GrowingBugs; any missing or mislabeled defects may bias results. Coverage metrics depend on the instrumentation tool (Cobertura ); failures to instrument generated tests or exclusions in configuration could lead to under- or over-reporting.
Internal Validity. We mitigate threats to internal validity through several measures. First, AdverTest is compared against four state-of-the-art baselines, and statistical analysis is applied to ensure significance. Experiments are replicated across multiple LLMs to verify that observed gains are not artifacts of a specific model. Second, we address potential data leakage. Defects were intentionally selected from GrowingBugs entries added in December 2024, after the DeepSeek V3 knowledge cutoff, to reduce the risk of models having prior exposure. Nevertheless, parts of the underlying projects may have existed earlier and could have been seen by LLMs, which may still introduce subtle leakage effects. Third, the RQ2 ablation (Section 5.2) uses a 50-bug random sub-sample of RQ1’s 200 bugs for compute reasons; we therefore read it only for component-wise comparisons under matched conditions, not as absolute effectiveness claims. Finally, while LLM nondeterminism presents an inherent validity threat, our diverse model selection and large-scale testing help ensure the robustness of reported results.
External Validity. Our evaluation spans both Java and Python, covering Defects4J and GrowingBugs for Java as well as 12 post-cutoff real-world issues from SWE-Rebench for Python. These results provide initial evidence that AdverTest is not tied to a single language, benchmark, or test framework. Nevertheless, the current study still covers only two programming ecosystems and a limited set of tools (e.g., JUnit/Cobertura and pytest/coverage.py); the Python generalization study is also smaller in scale than the Java evaluation. Regarding model selection, we evaluate AdverTest on three representative LLMs to approximate broader applicability, but computational constraints prevent exhaustive evaluation of the entire model landscape. Caution is therefore still needed when extrapolating our findings to other languages, domains, testing frameworks, mutation engines, or future LLM architectures.
Extending to Higher-Order Mutants
While our current framework focuses on first-order mutants for diagnosability and prompt reliability, a natural evolution is the generation of Higher-Order Mutants (HOMs), either by combining LLM-generated first-order mutants or by prompting the LLM for multi-line edits directly. HOMs can simulate subtle faults that arise from the interaction of multiple defects, but the added complexity may not be cost-effective: the Coupling Effect hypothesis suggests that test suites strong enough to kill simple mutants are already likely to kill complex ones. We leave a systematic study of this trade-off to future work.
Beyond Unit-Test Generation
The core philosophy of AdverTest—two LLM agents iteratively probing each other’s blind spots under structural and mutation feedback—is, in principle, not tied to unit testing. A natural extension is compiler fuzzing (e.g., WhiteFox ), where the connection between a mutation in the compiler source and the input program that distinguishes it is far less direct than a method call against a focal class. Adapting the feedback loop to such domains would require richer signals than the source diff and coverage map we use today—likely including IR-level execution traces and differential output checks—but we see this as a promising avenue for generalizing the adversarial dual-agent paradigm to more complex testing tasks.


