arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2604.22046cs.SEcs.AI
收藏

面向调用链的基于LLM的Java项目测试生成

Call-Chain-Aware LLM-Based Test Generation for Java Projects

Research Ireland Lero Centre for Software(爱尔兰Lero软件研究中心);University of Limerick(利默里克大学);University of Ottawa(渥太华大学);The State Key Laboratory of Blockchain and Data Security(区块链与数据安全国家重点实验室);Software Engineering Application Technology Lab, Huawei(华为软件工程应用技术实验室)

Guancheng Wang, Qinghua Xu, Lionel C. Briand, Zhaoqiang Guo, Kui Liu

AI总结:

本文提出CAT方法,通过静态分析整合调用链和依赖上下文,提升测试生成的覆盖率和有效性,实验显示其在Defects4J和真实项目中均优于现有方法。

摘要:

大型语言模型(LLM)近期在生成项目级单元测试方面展现出强大潜力。然而,现有最先进的方法主要依赖执行路径信息指导提示构造,这在复杂软件系统中往往不足。本文提出CAT,一种面向调用链的基于LLM的测试生成方法,通过专门的静态分析将调用链和依赖上下文显式整合到提示中。为构建可执行且语义有效的测试上下文,CAT系统地建模调用者-被调用者关系、对象构造函数和第三方依赖,并在生成失败时支持迭代测试修复。我们评估了CAT在广泛使用的Defects4J基准和四个真实世界GitHub项目上的表现。结果表明,在Defects4J的各个项目中,CAT在行覆盖率和分支覆盖率上分别比最先进的方法PANTA提高了18.04%和21.74%,并在截止日期后的现实项目中始终表现更优。消融研究进一步证明了调用链和依赖上下文在CAT中的重要性。

英文摘要:

Large language models (LLMs) have recently shown strong potential for generating project-level unit tests. However, existing state-of-the-art approaches primarily rely on execution-path information to guide prompt construction, which is often insufficient for complex software systems with rich inter-class dependencies, deep call chains, and intricate object initialization requirements. In this paper, we present CAT, a novel call-chain-aware LLM-based test generation approach that explicitly incorporates call-chain and dependency contexts into prompts through dedicated static analysis. To construct executable, semantically valid test contexts, CAT systematically models caller--callee relationships, object constructors, and third-party dependencies, and supports iterative test fixing when generation failures occur. We evaluate CAT on the widely used Defects4J benchmark and on four real-world GitHub projects released after the LLM's cut-off date, and compare it with the state-of-the-art LLM-based approach PANTA and the search-based tool EvoSuite. The results show that, across projects in Defects4J, CAT improves line coverage, branch coverage, and mutation score by 12.52, 12.97, and 14.39 percentage points (18.02%, 21.52%, and 26.94% relative), respectively, over PANTA, and by 9.67, 4.17, and 15.70 percentage points (13.37%, 6.04%, and 30.13% relative) over EvoSuite. On the post-cutoff projects, CAT also achieves the highest average line coverage, branch coverage, and mutation score among all compared approaches. An ablation study further demonstrates the importance of call-chain and dependency contexts in CAT.

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

↑