Large Language Models for Unit Testing: A Systematic Literature Review

Quanjun Zhang, Chunrong Fang, Siqi Gu, Ye Shang, Zhenyu Chen, Liang XiaoarXiv 2025 · DOI

Introduction

Unit testing is a cornerstone of software quality assurance, yet it remains one of the most labor-intensive phases of the development lifecycle, often consuming over 15% of a developer's time. The recent emergence of Large Language Models (LLMs) has sparked a surge of interest in automating these tasks. However, the rapid pace of publication has left the research landscape fragmented. This paper provides the first systematic literature review (SLR) of LLM-based unit testing, analyzing 105 high-quality studies to map out current achievements, methodologies, and remaining gaps.

Methodology

To ensure a comprehensive and unbiased review, the authors employed a "Quasi-Gold Standard" selection strategy. This involved a manual search of top-tier software engineering venues (such as ICSE, FSE, and ASE) to establish a seed set, followed by automated database queries and a "snowballing" process to capture missing citations. Each paper was subjected to a 10-point quality assessment.

The resulting corpus was analyzed through a dual-perspective taxonomy: the Unit Testing Perspective, which focuses on specific tasks and evaluation metrics, and the LLM Perspective, which examines model selection and utilization strategies.

Taxonomy of LLM-based unit testing research.

The Rapidly Evolving Landscape

The field has experienced exponential growth in a remarkably short window. While only a single relevant paper was identified in 2021, the number of publications surged to 73 in 2024 alone. This growth is largely driven by the accessibility of powerful commercial models and the increasing availability of open-source alternatives.

Growth of publications and distribution across research venues.

As shown in the distribution analysis, a significant portion of this research (40%) is currently hosted on arXiv, reflecting the speed of the field. Among peer-reviewed venues, the International Conference on Software Engineering (ICSE) leads the way, accounting for 11% of the literature.

Key Insights from the Literature

1. Skewed Task Focus

Research is heavily concentrated on Test Case Generation (~60%) and Oracle/Assertion Generation (~20%). While LLMs show great promise here, other critical areas remain underexplored. Tasks such as test evolution (maintaining tests as code changes), test readability, and the detection of "test smells" (poorly designed tests) represent significant opportunities for future research.

2. Prompting vs. Fine-Tuning

Prompt engineering is the dominant paradigm, utilized in 96 of the reviewed studies. Zero-shot and few-shot prompting are the most common approaches due to their low barrier to entry. While fine-tuning (used in 43 studies) can produce more specialized results, researchers often favor prompting OpenAI’s GPT-3.5 and GPT-4 or Meta’s CodeLlama for their general reasoning capabilities.

3. The Evaluation Disconnect

A critical finding of this review is the "Real Bug Illusion." Most studies evaluate AI-generated tests using traditional metrics like code coverage, pass rates, or compilation rates. However, high coverage does not necessarily equate to high utility. Only 8 of the reviewed papers measured the ability of generated tests to detect real-world bugs. Evidence suggests that while LLMs can achieve high coverage, they often fail to catch complex, real-world defects, with one study noting that GPT-4 detected fewer than 10% of bugs in a standard benchmark.

Challenges and Future Directions

  • Context and Dependencies: Current models struggle with the complex cross-file dependencies found in industrial software. Future work must focus on better context-retrieval mechanisms to provide LLMs with the necessary project-wide information without exceeding context windows.
  • Hybrid Systems: The most effective current systems are hybrids that combine LLMs with traditional static analysis or search-based testing tools. These tools provide the "guardrails" necessary to prevent hallucinations and ensure code compilability.
  • Specialized Models: There is a growing need for medium-sized, open-source LLMs pre-trained specifically on testing objectives. This would address both the high cost of commercial APIs and the privacy concerns of companies hesitant to share proprietary code.
  • Multi-modal Intent: Beyond source code, future tools should incorporate documentation, bug reports, and requirements to better understand the intent of the software, leading to more meaningful and accurate test oracles.

Summary updated

BibTeX
@misc{zhang2025large,
  author = {Quanjun Zhang and Chunrong Fang and Siqi Gu and Ye Shang and Zhenyu Chen and Liang Xiao},
  title = {{Large Language Models for Unit Testing: A Systematic Literature Review}},
  year = {2025},
  eprint = {2506.15227},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.15227},
}
Figure