Journal of Computer Applications

    Next Articles

Unit test case generation based on path guidance and iterative optimization#br#
#br#

DONG Yukun1,2,3, LIU Xiaoshan1,2,3, LIU Shuai1,2,3, MENG Xinran1,2,3, WEN Yunhao4   

  1. 1. Qingdao Institute of Software & College of Computer Science and Technology, China University of Petroleum (East China) 2. Shandong Key Laboratory of Intelligent Oil & Gas Industrial Software (China University of Petroleum (East China)) 3. State Key Lab. for Novel Software Technology (Nanjing University) 4. PetroChina Planning & Engineering Institute
  • Received:2025-10-09 Revised:2025-12-10 Online:2025-12-26 Published:2025-12-26
  • About author:DONG Yukun, born in 1981, Ph. D., associate professor. His research interests include intelligent software engineering, program analysis. LIU Xiaoshan, born in 2001, M. S. candidate. Her research interests include intelligent software engineering. LIU Shuai, born in 2000, M. S. candidate. His research interests include intelligent software engineering. MENG Xinran, born in 2002, M. S. candidate. Her research interests include intelligent software engineering. WEN Yunhao, born in 1985, M. S. His research interests include intelligent software engineering.
  • Supported by:
    Shandong Provincial Natural Science Foundation (ZR2024MF129); Open Proposal of the National Key Laboratory of Novel Software Technology (KFKT2025B80), Nanjing University; Graduate Course Development Project, China University of Petroleum (East China) (UPCYZH-2025-13)

基于路径引导与迭代优化的单元测试用例生成方法

董玉坤1,2,3,刘笑杉1,2,3,刘帅1,2,3,孟欣然1,2,3,文韵豪4   

  1. 1.中国石油大学(华东) 青岛软件学院、计算机科学与技术学院 2.山东省智能油气工业软件重点实验室(中国石油大学(华东)) 3.计算机软件新技术全国重点实验室(南京大学) 4.中国石油规划总院
  • 通讯作者: 董玉坤
  • 作者简介:董玉坤(1981—),男,山东济宁人,副教授,博士,CCF会员,主要研究方向:智能化软件工程、程序分析;刘笑杉(2001—),女,山东德州人,硕士研究生,CCF会员,主要研究方向:智能化软件工程;刘帅(2000—),男,山东枣庄人,硕士研究生,主要研究方向:智能化软件工程;孟欣然(2002—),女,山东济南人,硕士研究生,主要研究方向:智能化软件工程;文韵豪(1985—),男,四川德阳人,硕士,主要研究方向:智能化软件工程。
  • 基金资助:
    山东省自然科学基金资助项目(ZR2024MF129);南京大学计算机软件新技术全国重点实验室开放课题(KFKT2025B80);中国石油大学(华东)研究生课程建设项目(UPCYZH-2025-13)

Abstract: Large language model (LLM) has shown considerable potential in the automatic generation of unit test cases, yet limitations remain in covering complex structures and critical paths, resulting in gaps in coverage and accuracy. To address this issue, a path guidance iterative optimization strategy was proposed, integrating control flow graph analysis with a C-P-R (Context-Prompt-Response) template to enhance path guidance during test generation. In addition, a dual-verification mechanism was introduced to improve the reliability of generated cases, while iterative refinement was employed to progressively fill coverage blind spots. Experiments were conducted across multiple models and task scenarios, with systematic evaluations on key metrics including statement coverage, branch coverage, and assertion accuracy. Experimental results demonstrated that the proposed strategy achieved an average of 97% statement coverage and 94% branch coverage, while maintaining strong adaptability and stability across different models. These findings indicate that the combination of path guidance and iterative optimization significantly enhances the coverage and reliability of automatically generated test cases, providing a feasible new approach for automated testing and verification of complex software systems.

Key words: Large Language Model (LLM), unit test case generation, path guidance, iterative optimization, control flow graph analysis

摘要: 摘 要: 大语言模型(LLMs)在自动生成单元测试用例方面展现出显著潜力,但在覆盖复杂结构和关键路径时仍存在不足,导致生成结果在覆盖率与准确性上存在差距。为解决这一问题,提出一种路径引导与迭代优化策略,通过结合控制流图分析与C-P-R(Context-Prompt-Response)模板,强化测试用例生成过程中的路径引导能力。在此基础上,引入双重验证机制提升用例的可靠性,并通过迭代优化逐步弥补覆盖盲区。实验设计涵盖多种模型与任务场景,对语句覆盖率、分支覆盖率及断言准确率等关键指标进行了系统评估。实验结果显示,该策略能够在语句覆盖率上达到平均97%,在分支覆盖率上达到94%,同时在不同模型中均表现出较好的适应性与稳定性。研究表明,路径引导与迭代优化相结合能够有效提升测试用例生成的覆盖水平与可靠性,为复杂软件系统的自动化测试验证提供了可行的新思路。

关键词: 大语言模型, 单元测试用例生成, 路径引导, 迭代优化, 控制流图分析

CLC Number: