arXiv:2503.13580cs.SEcs.AI2025-03中稿 · publication in 202…被引 31

用迭代分析提升LLM生成测试用例的覆盖率。

LLM Test Generation via Iterative Hybrid Program Analysis

  • 结合静态控制流与动态覆盖分析,引导LLM识别未覆盖路径。
  • 在高复杂度代码上实现26%线覆盖率和23%分支覆盖率提升。
  • 适合需要高测试覆盖率的软件工程团队使用。

自动化单元测试生成仍是重大挑战,尤其针对真实项目中的复杂方法。尽管大型语言模型(LLMs)在代码生成方面取得进展,但受限于对复杂控制流结构的理解能力,难以达到高分支覆盖率。为此,我们提出Panta,一种模拟人类开发者分析代码并构建测试用例的迭代过程的技术。Panta融合静态控制流分析与动态代码覆盖分析,系统性地指导LLM识别未覆盖的执行路径,并生成更优的测试用例。通过引入迭代反馈机制,该技术基于静态与动态路径覆盖率的洞察持续优化测试生成,确保更全面有效的测试。我们在开源项目中高环路复杂度类上的实证评估表明,Panta相比当前最先进方法,实现了26%更高的行覆盖率和23%更高的分支覆盖率。

原文摘要 · Abstract (English)

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.

测试生成LLM代码分析

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