arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2503.13580cs.SEcs.AI
收藏

通过迭代混合程序分析进行 LLM 测试生成

LLM Test Generation via Iterative Hybrid Program Analysis

University of British Columbia(不列颠哥伦比亚大学)

Sijia Gu, Noor Nashid, Ali Mesbah

AI总结:

本文提出 Panta,通过结合静态控制流与动态覆盖率分析及迭代反馈引导 LLM 生成单元测试,在高复杂度类上显著提升行覆盖率和分支覆盖率。

摘要:

自动化单元测试生成仍然是一项重大挑战,尤其是对于真实项目中的复杂方法。尽管大型语言模型(LLM)在代码生成方面已取得进展,但由于其推理复杂控制流结构的能力有限,它们难以实现较高的分支覆盖率。为解决这一局限,我们提出了 Panta,该技术模拟人类开发者在分析代码并构造测试用例时遵循的迭代过程。Panta 集成了静态控制流分析和动态代码覆盖率分析,以系统性地引导 LLM 识别未覆盖的执行路径并生成更好的测试用例。通过引入迭代反馈驱动机制,我们的技术基于静态和动态路径覆盖洞察持续优化测试生成,从而确保更全面、有效的测试。我们针对开源项目中具有高圈复杂度的类进行了实证评估,结果表明,与最先进方法相比,Panta 的行覆盖率提高 26%,分支覆盖率提高 23%。

英文摘要:

Automating unit test generation remains a significant challenge, particularly for complex methods in real-world projects. While Large Language Models (LLMs) have made strides in code generation, they struggle to achieve high branch coverage due to their limited ability to reason about intricate control flow structures. To address this limitation, we introduce Panta, a technique that emulates the iterative process human developers follow when analyzing code and constructing test cases. Panta integrates static control flow analysis and dynamic code coverage analysis to systematically guide LLMs in identifying uncovered execution paths and generating better test cases. By incorporating an iterative feedback-driven mechanism, our technique continuously refines test generation based on static and dynamic path coverage insights, ensuring more comprehensive and effective testing. Our empirical evaluation, conducted on classes with high cyclomatic complexity from open-source projects, demonstrates that Panta achieves 26% higher line coverage and 23% higher branch coverage compared to the state-of-the-art.

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

↑