A Path-Guided and Iterative Optimization Strategy for Unit Test Case Generation with Large Language Models
The rise of Large Language Models (LLMs) has significantly impacted software engineering, particularly in automating unit test case generation. However, current methods often fall short of achieving comprehensive test coverage, especially for complex code structures and critical execution paths. This paper presents a novel Path-Guided and Iterative Optimization Strategy for unit test case generation. By integrating LLMs with Control Flow Graph (CFG) analysis and iterative refinement, the strategy efficiently identifies untested execution paths, improves test coverage, and enhances test case accuracy. The proposed strategy employs a Path-Guided method, utilizing CFG analysis to explore reachable basic paths. It integrates Path-Guided contextual information with LLMs and applies C-P-R (Context-Prompt-Response) templated guidance to generate high-quality unit test cases. A Dual Validation mechanism ensures the assertion accuracy and reliability of the initial test cases, followed by Iterative Optimization, which progressively refines test cases to address coverage gaps. The experimental results demonstrate that the proposed strategy significantly enhances the quality of generated test cases. Using the Path-Guided and Iterative Optimization strategy, the method achieves a maximum of 97% line coverage and 94% branch coverage while also improving the precision of test cases.
Authors
- Yukun Dong (ORCID: https://orcid.org/0000-0003-0787-5806)
- Xiaoshan Liu (ORCID: https://orcid.org/0000-0003-2373-9089)
- Shuo Wang
- Mingcheng Chen
- Xinran Meng
- Shuai Liu
- Zhikun Lv (ORCID: https://orcid.org/0009-0009-9071-1693)
Institutions
- Twitter (United States) (US)
Publication Details
- Journal
- International Journal of Software Engineering and Knowledge Engineering
- Published
- 2026-09-10
- DOI
- https://doi.org/10.1142/s021819402650083x
- Primary Topic
- Software Testing and Debugging Techniques
- Type
- article
- Field-Weighted Citation Impact
- 0.00