一句话:Panta 通过静态控制流与动态覆盖率的迭代反馈引导 LLM 生成测试,显著提升覆盖率。
自动化单元测试生成对真实项目中的复杂方法仍具挑战。LLM 虽在代码生成上取得进展,但因难以推理复杂控制流结构,分支覆盖率往往不高。本文提出 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.