计算机科学 ›› 2026, Vol. 53 ›› Issue (8): 365-374.doi: 10.11896/jsjkx.250900162

• 计算机软件 • 上一篇    下一篇

基于大语言模型的程序故障诊断测试用例生成与排序

樊如新1, 孙百才1, 宫丽娜2, 姚香娟3, 巩敦卫1   

  1. 1 青岛科技大学信息科学技术学院 山东 青岛 266000
    2 南京航空航天大学计算机科学与技术学院 南京 220000
    3 中国矿业大学数学学院 江苏 徐州 221000
  • 收稿日期:2025-09-28 修回日期:2025-12-11 出版日期:2026-08-15 发布日期:2026-08-17
  • 通讯作者: 巩敦卫(dwgong@vip.163.com)
  • 作者简介:(15192460210@163.com)
  • 基金资助:
    山东省自然科学基金重大基础研究项目(ZR2023ZD06);国家自然科学基金(62302502)

Test Case Generation and Prioritization for Program Fault Diagnosis Based on Large LanguageModel

FAN Ruxin1, SUN Baicai1, GONG Lina2, YAO Xiangjuan3, GONG Dunwei1   

  1. 1 School of Information Science and Technology, Qingdao University of Science and Technology, Qingdao, Shandong 266000, China
    2 School of Computer Science and Technology, Nanjing University of Aeronautics and Astronautics, Nanjing 220000, China
    3 School of Mathematics, China University of Mining and Technology, Xuzhou, Jiangsu 221000, China
  • Received:2025-09-28 Revised:2025-12-11 Published:2026-08-15 Online:2026-08-17
  • About author:FAN Ruxin,born in 2002,postgraduate.Her main research interests include software testing and test automation.
    GONG Dunwei,born in 1970,Ph.D,professor,Ph.D supervisor,is a member of CCF(No.31204D).His main research interests include intelligent optimization and software testing.
  • Supported by:
    Major Basic Research Project of Natural Science Foundation of Shandong Province(ZR2023ZD06) and National Natural Science Foundation of China(62302502).

摘要: 近年来,大语言模型(Large Language Model,LLM)已被广泛应用于测试用例生成与排序,但其生成结果仍存在较高的错误率和语义偏差。研究表明,LLM 生成代码的可执行率仅约为 40%,其中约1/3的错误源于断言逻辑偏差。这一问题严重影响了测试用例在故障诊断中的有效性与可靠性。为此,提出一种基于大语言模型的程序故障诊断测试用例生成与排序方法。首先,基于 LLM 提取原程序的代码摘要,用于生成实现相同功能的替身程序;然后,利用 LLM 生成原程序的初始测试用例,并基于多个替身程序优化其预期输出;接着,比较原程序与替身程序的测试输出差异,并结合原程序中函数的调用关系,对测试用例进行优先级排序;最后,基于排序结果高效诊断程序故障。针对 7 个问题和 140 个 Python 程序进行的实验结果表明,该方法显著降低了 LLM 生成测试用例的错误率;生成的测试用例序列在多个大语言模型下均能覆盖绝大多数程序故障函数,平均故障检测率(APFD)稳定保持在 0.75 以上,进一步验证了所提方法在提高测试准确性与故障诊断效率方面的有效性。

关键词: 大语言模型, 程序故障检测, 测试用例生成, 测试用例排序

Abstract: In recent years,large language model(LLM) have been widely applied to test case generation and prioritization.However,existing studies show that LLM-generated test cases still suffer from high error rates and semantic deviations.Empirical evaluations indicate that only about 40% of the generated code is directly executable,with roughly one-third of the failures caused by assertion logic errors.These issues significantly undermine the effectiveness and reliability of LLM-based fault diagnosis.To address this problem,this paper proposes a fault diagnosis-oriented test case generation and prioritization method based on LLM.Firstly,the proposed approach extracts code summaries from the original program using an LLM to generate substitute programs that implement equivalent functionality.Then,the LLM is employed to produce initial test cases,whose expected outputs are refined through multiple substitute programs.Next,the differences between the outputs of the original and substitute programs are analyzed,and test cases are prioritized based on the function call relationships of the original program.Finally,program faults are diagnosed efficiently according to the prioritized sequence.Experiments are conducted on seven benchmark problems comprising 140 Python programs.The results demonstrate that the proposed method significantly reduces the error rate of LLM-generated test cases.The resulting test sequences achieve high fault coverage across multiple LLM,with an average fault detection rate(APFD) consistently above 0.75,confirming the proposed method’s effectiveness in improving test accuracy and fault diagnosis efficiency.

Key words: Large language model, Program fault detection, Test case generation, Test case prioritization

中图分类号: 

  • TP301
[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.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!