arXivDaily arXiv每日学术速递 周一至周五更新
北美退伍军人节(Veterans Day),12 日无更新
arXiv 2602.21997cs.SEcs.AIcs.LG
收藏

通过消除已覆盖代码增强基于LLM的测试生成

Enhancing LLM-Based Test Generation by Eliminating Covered Code

University of Notre Dame(诺丁汉大学);Washington State University(华盛顿州立大学)

WeiZhe Xu, Mengyu Liu, Fanxin Kong

AI总结:

本文提出一种基于LLM的单元测试生成方法,通过上下文检索和迭代测试生成与代码消除,提升复杂方法的测试覆盖率。

摘要:

自动化测试生成是软件质量保证的关键,覆盖率是确保彻底测试的关键指标。近年来,大型语言模型(LLM)在提高测试生成方面展现出潜力,特别是在实现更高覆盖率方面。然而,现有基于LLM的测试生成解决方案在处理复杂方法时表现不佳。为了解决这些问题,我们提出了一种可扩展的基于LLM的单元测试生成方法。我们的方法包括两个关键步骤。第一步是上下文信息检索,利用LLM和静态分析收集与被测复杂方法相关的上下文信息。第二步是迭代测试生成与代码消除,反复为代码片段生成单元测试,跟踪已实现的覆盖率,并选择性地删除已覆盖的代码段。这一过程简化了测试任务,并缓解了由于上下文过长导致的token限制或推理效果降低的问题。通过在开源项目上的全面评估,我们的方法在性能上优于最先进的基于LLM和搜索的方法,证明了其在复杂方法上实现高覆盖率的有效性。

英文摘要:

Automated test generation is essential for software quality assurance, with coverage rate serving as a key metric to ensure thorough testing. Recent advancements in Large Language Models (LLMs) have shown promise in improving test generation, particularly in achieving higher coverage. However, while existing LLM-based test generation solutions perform well on small, isolated code snippets, they struggle when applied to complex methods under test. To address these issues, we propose a scalable LLM-based unit test generation method. Our approach consists of two key steps. The first step is context information retrieval, which uses both LLMs and static analysis to gather relevant contextual information associated with the complex methods under test. The second step, iterative test generation with code elimination, repeatedly generates unit tests for the code slice, tracks the achieved coverage, and selectively removes code segments that have already been covered. This process simplifies the testing task and mitigates issues arising from token limits or reduced reasoning effectiveness associated with excessively long contexts. Through comprehensive evaluations on open-source projects, our approach outperforms state-of-the-art LLM-based and search-based methods, demonstrating its effectiveness in achieving high coverage on complex methods.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑