计算机科学 ›› 2026, Vol. 53 ›› Issue (8): 365-374.doi: 10.11896/jsjkx.250900162
樊如新1, 孙百才1, 宫丽娜2, 姚香娟3, 巩敦卫1
FAN Ruxin1, SUN Baicai1, GONG Lina2, YAO Xiangjuan3, GONG Dunwei1
摘要: 近年来,大语言模型(Large Language Model,LLM)已被广泛应用于测试用例生成与排序,但其生成结果仍存在较高的错误率和语义偏差。研究表明,LLM 生成代码的可执行率仅约为 40%,其中约1/3的错误源于断言逻辑偏差。这一问题严重影响了测试用例在故障诊断中的有效性与可靠性。为此,提出一种基于大语言模型的程序故障诊断测试用例生成与排序方法。首先,基于 LLM 提取原程序的代码摘要,用于生成实现相同功能的替身程序;然后,利用 LLM 生成原程序的初始测试用例,并基于多个替身程序优化其预期输出;接着,比较原程序与替身程序的测试输出差异,并结合原程序中函数的调用关系,对测试用例进行优先级排序;最后,基于排序结果高效诊断程序故障。针对 7 个问题和 140 个 Python 程序进行的实验结果表明,该方法显著降低了 LLM 生成测试用例的错误率;生成的测试用例序列在多个大语言模型下均能覆盖绝大多数程序故障函数,平均故障检测率(APFD)稳定保持在 0.75 以上,进一步验证了所提方法在提高测试准确性与故障诊断效率方面的有效性。
中图分类号:
| [1] BAREJA K,SINGHAL A.A review of estimation techniques to reduce testing efforts in software development[C]//2015 Fifth International Conference on Advanced Computing & Communication Technologies.IEEE,2015:541-546. [2] LI K,YUAN Y.Large language models as test case generators:Performance evaluation and enhancement[PP/OL].arXiv[2025-03-20].https://arxiv.org/abs/2404.13340. [3] MATTIS T,BÖHME L,KREBS E,et al.Faster Feedback with AI? A Test Prioritization Study[C]//Companion Proceedings of the 8th International Conference on the Art,Science,and Engineering of Programming.2024:32-40. [4] WANG C,PASTORE F,GOKNIL A,et al.Automatic generation of system test cases from use case specifications[C]//Proceedings of the 2015 International Symposium on Software Testing and Analysis.2015:385-396. [5] LIU J,XIA C S,WANG Y,et al.Is your code generated by chatgpt really correct? Rigorous evaluation of large language models for code generation[J].Advances in Neural Information Processing Systems,2023,36:21558-21572. [6] BALDONI R,COPPA E,D’ELIA D C,et al.A survey of symbolic execution techniques[J].ACM Computing Surveys(CSUR),2018,51(3):1-39. [7] JIA Y,HARMAN M.An analysis and survey of the development of mutation testing[J].IEEE Transactions on Software Engineering,2010,37(5):649-678. [8] PRADEL M,SEN K.Deepbugs:A learning approach to name-based bug detection[J].Proceedings of the ACM on Programming Languages,2018,2(OOPSLA):1-25. [9] HOSSAIN S B,JIANG N,ZHOU Q,et al.A deep dive into large language models for automated bug localization and repair[J].Proceedings of the ACM on Software Engineering,2024,1(FSE):1471-1493. [10] 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]//Proceedings of the 28th International Conference on Evaluation and Assessment in Software Engineering.2024:313-322. [11] SAHOO P,SINGH A K,SAHA S,et al.A systematic survey of prompt engineering in large language models:Techniques and applications[PP/OL].arXiv[2025-03-20].https://arxiv.org/abs/2402.07927. [12] SCHÄFER M,NADI S,EGHBALI A,et al.An empirical evaluation of using large language models for automated unit test generation[J].IEEE Transactions on Software Engineering,2023,50(1):85-105. [13] WANG Y,ZI Q C,PENG X,et al.A Method for Generating Fault Reproduction Test Cases Based on Large Language Mo-dels[J].Ruan Jian Xue Bao/Journal of Software,2026,37(4):1690-1714. [14] XIAO Z Q,SHI Y Q,QU Y B.Research on Optimization of Test Case Generation Based on Neuron Coverage Indicators[J].Computer Science,2025,52(11):339-348. [15] HOODA I,CHHILLAR R S.Test case optimization and redundancy reduction using GA and neural networks[J].International Journal of Electrical and Computer Engineering,2018,8(6):5449-5457. [16] ELBAUM S,MALISHEVSKY A G,ROTHERMEL G.Prioritizing test cases for regression testing[C]//Proceedings of the International Symposium on Software Testing and Analysis.2000:102-112. [17] LI Z,HARMAN M,HIERONS R M.Search algorithms for regression test case prioritization[J].IEEE Transactions on Software Engineering,2007,33(4):225-237. [18] TONELLA P,AVESANI P,SUSI A.Using the case-basedranking methodology for test case prioritization[C]//2006 22nd IEEE International Conference on Software Maintenance.IEEE,2006. [19] LACHMANN R,SCHULZE S,NIEKE M,et al.System-level test case prioritization using machine learning[C]//2016 15th IEEE International Conference on Machine Learning and Applications(ICMLA).IEEE,2016. [20] SHARIF A,MARIJAN D,LIAAEN M.Deeporder:Deep lear-ning for test case prioritization in continuous integration testing[C]//2021 IEEE International Conference on Software Maintenance and Evolution(ICSME).IEEE,2021. [21] LI Y,LI M,LAI Q,et al.Testrank:Bringing order into unlabeled test instances for deep learning tasks[J].Advances in Neural Information Processing Systems,2021,34:20874-20886. [22] LI T O,ZONG W,WANG Y,et al.Nuances are the key:Unlo-cking chatgpt to find failure-inducing tests with differential prompting[C]//2023 38th IEEE/ACM International Confe-rence on Automated Software Engineering(ASE).IEEE,2023:14-26. [23] CODEFORCES.Codeforces[EB/OL].[2025-03-20].https://codeforces.com/. [24] OPENAI.GPT-4[EB/OL].[2025-03-20].https://openai.com/zh-Hans-CN/index/gpt-4/. [25] META.Llama[EB/OL].[2025-03-20].https://www.llama-cn.com/. [26] ANTHROPIC.Claude AI[EB/OL].[2025-03-20].https://claude.ai/login. |
|
||