Abstract
While Large Language Models (LLMs) are widely recognized for their code synthesis capabilities, their proficiency in program testing remains less explored. This study systematically evaluates 11 LLMs across various testing scenarios, revealing that models generate higher-quality test cases when prompted with their own self-generated code. Furthermore, a strong correlation exists between a model's coding and testing abilities, and the reliability of generated test cases typically decays with subsequent iterations. These insights are leveraged to enhance AI-driven program synthesis frameworks, achieving significant performance gains.
Introduction
In the rapidly evolving landscape of code-centric Large Language Models (LLMs), evaluation has primarily focused on program synthesis—the ability to write functional code. However, in professional software engineering, testing is equally vital. While traditional automated tools like fuzzers excel at finding edge cases, they often lack an understanding of semantic intent. LLMs, with their natural language processing strengths, offer a promising alternative for generating unit tests from docstrings. This paper investigates how different LLMs handle test case generation and how the context provided in the prompt influences test quality.
Methodology
The researchers evaluated 11 LLMs, ranging from 1B-parameter models like InCoder to state-of-the-art systems like GPT-3.5-turbo. The evaluation spanned four distinct scenarios:
- Self-generated: The model generates tests for its own synthesized code.
- Cross-generated: The model generates tests for code produced by another model.
- Oracle: The model generates tests for ground-truth "perfect" code.
- Placeholder: The model generates tests based solely on the function signature and docstring.
Success was measured using Pass Rate (correctness of input-output pairs) and Coverage Rate (logic exercise). The study utilized the HumanEval+ and MBPP (Sanitized) benchmarks to ensure rigorous evaluation.
Key Insights
The "Self-Generation" Advantage
Prompting a model with its own code implementation significantly improves test case quality compared to using a simple placeholder. Writing the code first appears to serve as a reasoning step, allowing the model to "internalize" the problem's logic before attempting to verify it.
Confidence Decay in Test Generation
A critical observation is that the first test case generated in a batch is typically the most accurate. As the model continues to generate subsequent test cases within the same block, the correctness rate tends to decline.
Correlation Between Coding and Testing
The study found a strong positive correlation between a model’s ability to synthesize correct code and its ability to generate valid tests. Top-tier "coders" generally prove to be top-tier "testers," suggesting that these two skills draw from a shared underlying understanding of programming logic.
Results and Impact
By integrating these findings into the CodeT framework through Self-Generation (SG) and Rank-based Re-weighting (RW), the researchers achieved a +11.77% improvement in code pass rates on HumanEval+ compared to the GPT-3.5-turbo baseline. This approach outperformed the previous state-of-the-art by +4.22%. While closed-source models like GPT-3.5-turbo led the rankings, open-source models like WizardCoder demonstrated significant competitive potential.
Conclusion
LLMs possess a remarkable, yet underutilized, ability to test code. By understanding the nuances of how these models generate tests—such as the benefits of self-contextualization and the phenomenon of confidence decay—developers can significantly boost the reliability of AI-assisted programming. Future work will explore iterative debugging loops to further bridge the gap between AI-generated code and robust, production-ready software.
Summary updated