Journal of Computer Applications ›› 2026, Vol. 46 ›› Issue (11): 3598-3606.DOI: 10.11772/j.issn.1001-9081.2025091177
• Computer software technology • Previous Articles
Yukun DONG1,2,3(
), Xiaoshan LIU1,2,3, Shuai LIU1,2,3, Xinran MENG1,2,3, Yunhao WEN4
Received:2025-10-11
Revised:2025-12-10
Accepted:2025-12-15
Online:2025-12-26
Published:2026-11-10
Contact:
Yukun DONG
About author:LIU Xiaoshan, born in 2001, M. S. candidate. Her research interests include intelligent software engineering.Supported by:
董玉坤1,2,3(
), 刘笑杉1,2,3, 刘帅1,2,3, 孟欣然1,2,3, 文韵豪4
通讯作者:
董玉坤
作者简介:刘笑杉(2001—),女,山东德州人,硕士研究生,CCF会员,主要研究方向:智能化软件工程基金资助:CLC Number:
Yukun DONG, Xiaoshan LIU, Shuai LIU, Xinran MENG, Yunhao WEN. Unit test case generation method based on path guidance and iterative optimization[J]. Journal of Computer Applications, 2026, 46(11): 3598-3606.
董玉坤, 刘笑杉, 刘帅, 孟欣然, 文韵豪. 基于路径引导与迭代优化的单元测试用例生成方法[J]. 《计算机应用》唯一官方网站, 2026, 46(11): 3598-3606.
Add to citation manager EndNote|Ris|BibTeX
URL: https://www.joca.cn/EN/10.11772/j.issn.1001-9081.2025091177
| 方法 | 综合 覆盖率 | 基本路径 覆盖率 | 断言 准确率 | 冗余率 | 输入多样性 |
|---|---|---|---|---|---|
| 只有基础提示语 | 0.60 | 0.40 | 0.308 3 | 0.25 | 0.63 |
| 函数级上下文 | 0.67 | 0.46 | 0.421 5 | 0.22 | 0.72 |
| 路径级上下文 | 0.77 | 0.58 | 0.465 2 | 0.18 | 0.78 |
函数级和路径级 上下文 | 0.79 | 0.60 | 0.490 8 | 0.15 | 0.82 |
Tab. 1 Impact of different contexts on test results
| 方法 | 综合 覆盖率 | 基本路径 覆盖率 | 断言 准确率 | 冗余率 | 输入多样性 |
|---|---|---|---|---|---|
| 只有基础提示语 | 0.60 | 0.40 | 0.308 3 | 0.25 | 0.63 |
| 函数级上下文 | 0.67 | 0.46 | 0.421 5 | 0.22 | 0.72 |
| 路径级上下文 | 0.77 | 0.58 | 0.465 2 | 0.18 | 0.78 |
函数级和路径级 上下文 | 0.79 | 0.60 | 0.490 8 | 0.15 | 0.82 |
| 方法 | 语句覆盖率 | 分支覆盖率 | 基本路径覆盖率 |
|---|---|---|---|
| 动态执行反馈 | 0.90 | 0.89 | 0.80 |
| 覆盖率缺口分析 | 0.91 | 0.90 | 0.80 |
| 以上两种方法相结合 | 0.97 | 0.94 | 0.90 |
Tab. 2 Impact of different strategies on iterative optimization
| 方法 | 语句覆盖率 | 分支覆盖率 | 基本路径覆盖率 |
|---|---|---|---|
| 动态执行反馈 | 0.90 | 0.89 | 0.80 |
| 覆盖率缺口分析 | 0.91 | 0.90 | 0.80 |
| 以上两种方法相结合 | 0.97 | 0.94 | 0.90 |
| 引导策略 | 模型 | 覆盖率 | 输入多样性 | 冗余率 | ||
|---|---|---|---|---|---|---|
| 综合覆盖率 | 基本路径覆盖率 | 断言准确率 | ||||
| 基础提示引导 | GPT-4o | 0.60 | 0.40 | 0.308 3 | 0.63 | 0.25 |
| Gemini 1.5 Pro | 0.56 | 0.33 | 0.260 5 | 0.57 | 0.30 | |
| CodeGen2 | 0.49 | 0.30 | 0.236 1 | 0.41 | 0.50 | |
| 路径引导 | GPT-4o | 0.79 | 0.60 | 0.490 8 | 0.82 | 0.15 |
| Gemini 1.5 Pro | 0.73 | 0.55 | 0.445 2 | 0.74 | 0.22 | |
| CodeGen2 | 0.68 | 0.51 | 0.377 8 | 0.61 | 0.34 | |
Tab. 3 Comparison of performance metrics for test cases generated by LLMs under various guidance strategies
| 引导策略 | 模型 | 覆盖率 | 输入多样性 | 冗余率 | ||
|---|---|---|---|---|---|---|
| 综合覆盖率 | 基本路径覆盖率 | 断言准确率 | ||||
| 基础提示引导 | GPT-4o | 0.60 | 0.40 | 0.308 3 | 0.63 | 0.25 |
| Gemini 1.5 Pro | 0.56 | 0.33 | 0.260 5 | 0.57 | 0.30 | |
| CodeGen2 | 0.49 | 0.30 | 0.236 1 | 0.41 | 0.50 | |
| 路径引导 | GPT-4o | 0.79 | 0.60 | 0.490 8 | 0.82 | 0.15 |
| Gemini 1.5 Pro | 0.73 | 0.55 | 0.445 2 | 0.74 | 0.22 | |
| CodeGen2 | 0.68 | 0.51 | 0.377 8 | 0.61 | 0.34 | |
| 方法 | 语句覆盖率 | 分支覆盖率 | 基本路径覆盖率 |
|---|---|---|---|
| Pynguin | 0.75 | 0.68 | 0.60 |
| 基础提示 | 0.62 | 0.55 | 0.48 |
| 路径引导 | 0.78 | 0.70 | 0.64 |
| 路径引导+迭代优化 | 0.91 | 0.85 | 0.81 |
Tab. 4 Comparison of test coverage between proposed strategy and Pynguin on BugsInPy subset
| 方法 | 语句覆盖率 | 分支覆盖率 | 基本路径覆盖率 |
|---|---|---|---|
| Pynguin | 0.75 | 0.68 | 0.60 |
| 基础提示 | 0.62 | 0.55 | 0.48 |
| 路径引导 | 0.78 | 0.70 | 0.64 |
| 路径引导+迭代优化 | 0.91 | 0.85 | 0.81 |
| [1] | Chen M, Tworek J, Jun H, et al. Evaluating large language models trained on code[PP/OL]. V2. arXiv (2021-07-14) [2025-03-22].. |
| [2] | Li Y, Choi D, Chung J, et al. Competition-level code generation with AlphaCode[J]. Science, 2022, 378(6624): 1092-1097. |
| [3] | Rozière B, Zhang J M, Charton F, et al. Leveraging automated unit tests for unsupervised code translation[PP/OL]. V2. arXiv (2022-02-16) [2025-03-02].. |
| [4] | Chen X, Liu C, Song D. Execution-guided neural program synthesis[EB/OL]. (2023-05-06) [2025-04-11].. |
| [5] | Tang Y, Liu Z, Zhou Z, et al. ChatGPT vs SBST: a comparative assessment of unit test suite generation[J]. IEEE Transactions on Software Engineering, 2024, 50(6): 1340-1359. |
| [6] | Ahmad W U, Chakraborty S, Ray B, et al. A Transformer-based approach for source code summarization[C]// ACL 2020. Stroudsburg: ACL, 2020: 4998-5007. |
| [7] | Allamanis M, Barr E T, Bird C, et al. Suggesting accurate method and class names[C]// ESEC/FSE 2015. New York: ACM, 2015: 38-49. |
| [8] | Dinella E, Ryan G, Mytkowicz T, et al. TOGA: a neural method for test oracle generation[C]// ICSE 2022. New York: ACM, 2022: 2130-2141. |
| [9] | Chen Y, Hu Z, Zhi C, et al. ChatUniTest: a framework for LLM-based test generation[C]// FSE 2024. New York: ACM, 2024: 572-576. |
| [10] | Dakhel A M, Nikanjam A, Majdinasab V, et al. Effective test generation using pre-trained large language models and mutation testing[J]. Information and Software Technology, 2024, 171: No.107468. |
| [11] | Yuan Z, Liu M, Ding S, et al. Evaluating and improving ChatGPT for unit test generation[J]. Proceedings of the ACM on Software Engineering, 2024, 1(FSE): No.76. |
| [12] | Ryan G, Jain S, Shang M, et al. Code-aware prompting: a study of coverage-guided test generation in regression setting using LLM[J]. Proceedings of the ACM on Software Engineering, 2024, 1(FSE): No.43. |
| [13] | Pizzorno J A, Berger E D. CoverUp: coverage-guided LLM-based test generation[J]. Proceedings of the ACM on Software Engineering, 2025, 2(FSE): No.FSE128. |
| [14] | de Moura L, Bjørner N . Z 3: an efficient SMT solver[C]// TACAS 2008, LNCS 4963. Berlin: Springer, 2008: 337-340. |
| [15] | Harman M, McMinn P. A theoretical and empirical study of search-based testing: local, global, and hybrid search[J]. IEEE Transactions on Software Engineering, 2010, 36(2): 226-247. |
| [16] | Delgado-Pérez P, Ramírez A, Valle-Gómez K J, et al. InterEvo-TR: interactive evolutionary test generation with readability assessment[J]. IEEE Transactions on Software Engineering, 2023, 49(4): 2580-2596. |
| [17] | Xiao X, Li S, Xie T, et al. Characteristic studies of loop problems for structural test generation via symbolic execution[C]// ASE 2013. Piscataway: IEEE, 2013: 246-256. |
| [18] | Pacheco C, Lahiri S K, Ernst M D, et al. Feedback-directed random test generation[C]// ICSE 2007. Piscataway: IEEE, 2007: 75-84. |
| [19] | Alagarsamy S, Tantithamthavorn C, Aleti A. A3Test: Assertion-Augmented Automated Test case generation[J]. Information and Software Technology, 2024, 176: No.107565. |
| [20] | Tufano M, Drain D, Svyatkovskiy A, et al. Unit test case generation with transformers and focal context[PP/OL]. V2. arXiv (2021-05-20) [2025-03-09]. . |
| [21] | Shin J, Hashtroudi S, Hemmati H, et al. Domain adaptation for code model-based unit test case generation[C]// ISSTA 2024. New York: ACM, 2024: 1211-1222.) |
| [22] | Steenhoek B, Tufano M, Sundaresan N, et al. Reinforcement learning from automatic feedback for high-quality unit test generation[C]// DeepTest 2025. Piscataway: IEEE, 2025: 37-44. |
| [23] | Vikram V, Lemieux C, Sunshine J, et al. Can large language models write good property-based tests?[PP/OL]. V2. arXiv (2024-07-22) [2025-02-11]. . |
| [24] | Plein L, Ouédraogo W C, Klein J, et al. Automatic generation of test cases based on bug reports: a feasibility study with large language models[C]// ICSE-Companion 2024. New York: ACM, 2024: 360-361. |
| [25] | Lemieux C, Inala J P, Lahiri S K, et al. CodaMosa: escaping coverage plateaus in test generation with pre-trained large language models[C]// ICSE 2023. Piscataway: IEEE, 2023: 919-931. |
| [26] | Bhatia S, Gandhi T, Kumar D, et al. Unit test generation using generative AI: a comparative performance analysis of autogeneration tools[C]// LLM4Code 2024. New York: ACM, 2024: 54-61. |
| [27] | Siddiq M L, da Silva Santos J C, Tanvir R H, et al. Using large language models to generate JUnit tests: an empirical study[C]// EASE 2024. New York: ACM, 2024: 313-322. |
| [28] | McCabe T J. A complexity measure[J]. IEEE Transactions on Software Engineering, 1976, SE-2(4): 308-320. |
| [29] | Li J, Chen P, Xia B, et al. MoTCoder: elevating large language models with modular of thought for challenging programming tasks[PP/OL]. V5. arXiv (2025-03-30) [2025-04-09].. |
| [30] | Team Gemini. Gemini 1.5: unlocking multimodal understanding across millions of tokens of context[PP/OL]. V5. arXiv (2024-12-16) [2025-03-10].. |
| [31] | Nijkamp E, Pang B, Hayashi H, et al. CodeGen: an open large language model for code with multi-turn program synthesis[PP/OL]. V5. arXiv (2023-02-27) [2025-02-18]. . |
| [32] | Lukasczyk S, Fraser G. Pynguin: automated unit test generation for python[C]// ICSE-Companion 2022. New York: ACM, 2022: 168-172. |
| [33] | Hendrycks D, Basart S, Kadavath S, et al. Measuring coding challenge competence with APPS[PP/OL]. V3. arXiv (2021-11-08) [2025-06-07]. . |
| [34] | Widyasari R, Sim S Q, Lok C, et al. BugsInPy: a database of existing bugs in python programs to enable controlled testing and debugging studies[C]// ESEC/FSE 2020. New York: ACM, 2020: 1556-1560. |
| [1] | Yun BIAN, Haiquan WANG, Yi CHEN, Zhe CUI. Construction method of software defect prediction dataset with explainability [J]. Journal of Computer Applications, 2026, 46(9): 2948-2958. |
| [2] | Zhenhui GONG, Xiaoyu SHI, Yun LU, Yangcheng LIU, Mingsheng SHANG. Fair recommendation framework for large language models with sensitive attribute absence [J]. Journal of Computer Applications, 2026, 46(9): 2838-2846. |
| [3] | Yaoran HUO, Huizhi LI, Dahe ZENG, Zhenyu TANG, Chenmei LIU, Yan WU, Xiao ZHANG, Siqin CHEN, Houhui YANG. Contract review framework based on dynamic rule generation and neuro-symbolic reasoning using large language models [J]. Journal of Computer Applications, 2026, 46(9): 2820-2826. |
| [4] | Mengjiao YU, Min JIN, Xinhua LIU. Agile enhancement development framework driven by human-multi-agent collaboration [J]. Journal of Computer Applications, 2026, 46(9): 2938-2947. |
| [5] | Yue ZHANG, Yuhan GUO. Ride-hailing spatio-temporal demand forecasting method via large language model-driven semantic quantification [J]. Journal of Computer Applications, 2026, 46(8): 2467-2476. |
| [6] | Mengting WANG, Shuanliang GAO, Wenrui LIAO, Geng LI, Jiaxing ZHANG, Yuanfang ZHU, Tiange ZHAO, Yonghui LIU, Hongru LIANG. Message consistency parsing framework for aviation domain [J]. Journal of Computer Applications, 2026, 46(8): 2681-2690. |
| [7] | Xinliang LIU, Yushi XU, Dubai LI, Yanzhao REN. Survey of knowledge graph-based question answering methods [J]. Journal of Computer Applications, 2026, 46(8): 2394-2410. |
| [8] | Jiahang LI, Qilong HAN, Lijie LI, Hui ZHANG. Large language model-driven method for qualifier enhancement in hyper-relational knowledge graphs [J]. Journal of Computer Applications, 2026, 46(7): 2043-2053. |
| [9] | Linkai ZHU, Lu YANG, Hongjie ZHANG, Zijin WU, Lu LIU. Smart contract generation framework driven by LLM and SWRL for cross-border data compliance across heterogeneous blockchains [J]. Journal of Computer Applications, 2026, 46(7): 2074-2084. |
| [10] | Yadian CHENG, Yingying LI, Ping ZHANG, Fangbing QIU, Xiaonan CHAI, Yuqiao SHU. Dual-role interaction mechanism-based large language model for psychological health [J]. Journal of Computer Applications, 2026, 46(7): 2054-2063. |
| [11] | Didi HOU, Shaodong HONG, Yujie FU, Yunhe CUI, Guowei SHEN. Cybersecurity named entity recognition method based on large language model linking [J]. Journal of Computer Applications, 2026, 46(7): 2064-2073. |
| [12] | Yuqi WANG, Yangsen ZHANG, Pu WANG. High school English reading comprehension model integrating knowledge augmentation and contrastive learning [J]. Journal of Computer Applications, 2026, 46(7): 2096-2103. |
| [13] | Yusheng YI, Zhaohao HUANG, Zihao DENG, Leilei KONG, Haoliang QI. CORER: collaborative multi-knowledge large language model prompt framework for IT application innovation database migration [J]. Journal of Computer Applications, 2026, 46(6): 1811-1817. |
| [14] | Taixin CAI, Fengfeng WEI. Large language model-enhanced ant colony optimization for multi-solution traveling salesman problems [J]. Journal of Computer Applications, 2026, 46(6): 1712-1720. |
| [15] | Jintao WANG, Zhilin GAO, Qixiang MENG, Fanliang BU. Legal case retrieval method via case information reformulation using large language model [J]. Journal of Computer Applications, 2026, 46(6): 1785-1792. |
| Viewed | ||||||
|
Full text |
|
|||||
|
Abstract |
|
|||||