arXiv:2604.22046cs.SEcs.AI2026-04

通过分析调用链和依赖关系,提升LLM生成Java单元测试的覆盖率和成功率。

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

论文配图:Call-Chain-Aware LLM-Based Test Generation for Java Projects
图 1 · 摘自论文原文
  • 基于静态分析显式建模调用链与依赖关系,增强提示工程
  • 在Defects4J上提升18.04%行覆盖率和21.74%分支覆盖率
  • 适用于复杂项目且支持失败后迭代修复,适合高依赖系统测试

大型语言模型(LLMs)在生成项目级单元测试方面展现出强大潜力。然而,现有最先进方法主要依赖执行路径信息引导提示构造,对具有丰富类间依赖、深层调用链和复杂对象初始化需求的复杂软件系统而言往往不足。本文提出CAT,一种新型调用链感知的LLM测试生成方法,通过专门的静态分析将调用链与依赖上下文显式融入提示中。为构建可执行、语义有效的测试上下文,CAT系统性地建模调用者-被调用者关系、对象构造器及第三方依赖,并在生成失败时支持迭代修复。我们在广泛使用的Defects4J基准数据集以及四个在LLM训练截止日期后的实际GitHub项目上评估了CAT。结果表明,在Defects4J各项目上,相较于最先进方法PANTA,CAT分别提升了18.04%的行覆盖率和21.74%的分支覆盖率;在截断日期后的实际项目中也持续表现更优。消融实验进一步验证了调用链与依赖上下文在CAT中的关键作用。

原文摘要 · Abstract (English)

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. The results show that, across projects in Defects4J, CAT improves line and branch coverage by 18.04% and 21.74%, respectively, over the state-of-the-art approach PANTA, while consistently achieving superior performance on post-cutoff real-world projects. An ablation study further demonstrates the importance of call-chain and dependency contexts in CAT.

测试生成LLM应用调用链分析Java测试

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。