A Path-Guided and Iterative Optimization Strategy for Unit Test Case Generation with Large Language Models
- 17 October 2026
- journal article
- Published by World Scientific Pub Co Pte Ltd in International Journal of Software Engineering and Knowledge Engineering
- p. 1-34
Abstract
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 Context-Prompt-Response (C–P–R) 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.Keywords
Funding Information
- Key Technology Research and Development Program of Shandong Province (2025CXPT104)
- Natural Science Foundation of Shandong Province (ZR2024MF129)
- Fundamental Research Funds for the Central Universities (26CX05052A)
This publication has 22 references indexed in Scilit:
- A3Test: Assertion-Augmented Automated Test case generationInformation and Software Technology, 2024
- Exploring Large Language Models for Method Name Prediction2024
- Effective test generation using pre-trained Large Language Models and mutation testingInformation and Software Technology, 2024
- CodaMosa: Escaping Coverage Plateaus in Test Generation with Pre-trained Large Language Models2023
- InterEvo-TR: Interactive Evolutionary Test Generation With Readability AssessmentIEEE Transactions on Software Engineering, 2022
- Characteristic studies of loop problems for structural test generation via symbolic execution2013
- A Theoretical and Empirical Study of Search-Based Testing: Local, Global, and Hybrid SearchIEEE Transactions on Software Engineering, 2009
- Z3: An Efficient SMT Solver2008
- Feedback-Directed Random Test Generation29th International Conference on Software Engineering (ICSE'07), 2007
- A Complexity MeasureIEEE Transactions on Software Engineering, 1976