[论文解读] Advancing Code Coverage: Incorporating Program Analysis with Large Language Models
TELPA通过使用基于程序分析的提示来覆盖难以覆盖的分支,提升基于LLM的测试生成,在27个Python项目上超过最先进的SBST和基于LLM的技术。它结合了向后对象构造分析、向前跨过程分析、反例引导和反馈循环。
Automatic test generation plays a critical role in software quality assurance. While the recent advances in Search-Based Software Testing (SBST) and Large Language Models (LLMs) have shown promise in generating useful tests, these techniques still struggle to cover certain branches. Reaching these hard-to-cover branches usually requires constructing complex objects and resolving intricate inter-procedural dependencies in branch conditions, which poses significant challenges for existing test generation techniques. In this work, we propose TELPA, a novel technique aimed at addressing these challenges. Its key insight lies in extracting real usage scenarios of the target method under test to learn how to construct complex objects and extracting methods entailing inter-procedural dependencies with hard-to-cover branches to learn the semantics of branch constraints. To enhance efficiency and effectiveness, TELPA identifies a set of ineffective tests as counter-examples for LLMs and employs a feedback-based process to iteratively refine these counter-examples. Then, TELPA integrates program analysis results and counter-examples into the prompt, guiding LLMs to gain deeper understandings of the semantics of the target method and generate diverse tests that can reach the hard-to-cover branches. Our experimental results on 27 open-source Python projects demonstrate that TELPA significantly outperforms the state-of-the-art SBST and LLM-based techniques, achieving an average improvement of 31.39% and 22.22% in terms of branch coverage.
研究动机与目标
- 说明SBST和常规LLM提示未覆盖的难以到达的分支的必要性。
- 提出TELPA,将向后/向前的方法调用分析整合以引导测试生成。
- 通过反例采样和基于反馈的提示循环提升效率。
- 展示TELPA在27个Python项目上对Pynguin和CODAMOSA的有效性。
提出的方法
- 使用现有工具进行先导的测试生成,以覆盖易覆盖的分支。
- 应用向后方法调用分析,提取以目标方法结束的对象构造序列。
- 进行向前方法调用分析,识别影响分支约束的所有方法。
- 从现有测试中抽样多样化的反例,以引导LLMs避开低效路径。
- 将程序分析结果和反例纳入LLM提示,并使用两阶段的Chain-of-Thought提示策略来生成多样化测试。
- 通过对比27个Python项目中分支覆盖率和代码覆盖率,与Pynguin和CODAMOSA进行评估。
实验结果
研究问题
- RQ1RQ1:相对于最先进的技术,TELPA在代码覆盖率方面提高了多少?
- RQ2RQ2:TELPA的主要组成部分(向后/向前分析、反例、反馈)如何影响性能?
- RQ3RQ3:先导工具的选择(Pynguin或CODAMOSA)以及LLM如何影响TELPA的性能?
主要发现
- TELPA在同一时间预算内,在分支覆盖率上平均比Pynguin高出31.39%,比CODAMOSA高出22.22%。
- TELPA在平均行覆盖率上比Pynguin高出15.67%,并在与CODAMOSA的可比范围内有类似提升。
- 在27个项目中,TELPA在初始易覆盖的分支瓶颈被克服后,持续提高覆盖率。
- 消融分析显示向后分析、向前分析、反例采样和反馈各自对性能提升有贡献。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。