提升代码覆盖率:将程序分析与大型语言模型相结合
Advancing Code Coverage: Incorporating Program Analysis with Large Language Models
AI总结:
针对自动测试生成难以覆盖复杂分支的问题,提出TELPA技术,通过提取真实使用场景和跨过程依赖方法,并结合反例与反馈机制优化LLM提示,显著提升了分支覆盖率。
摘要:
自动测试生成在软件质量保证中发挥着关键作用。尽管基于搜索的软件测试(SBST)和大型语言模型(LLMs)的最新进展在生成有用测试方面展现出潜力,但这些技术仍难以覆盖某些分支。要覆盖这些难以覆盖的分支,通常需要构造复杂对象并解析分支条件中错综复杂的跨过程依赖关系,这给现有的测试生成技术带来了巨大挑战。在本研究中,我们提出了TELPA,一种旨在解决这些挑战的新技术。其核心见解在于提取被测目标方法的真实使用场景以学习如何构造复杂对象,并提取包含难以覆盖分支的跨过程依赖的方法以学习分支约束的语义。为提升效率和有效性,TELPA识别出一组无效测试作为LLMs的反例,并采用基于反馈的过程迭代优化这些反例。然后,TELPA将程序分析结果和反例整合到提示中,引导LLMs更深入地理解目标方法的语义,并生成能够覆盖难以覆盖分支的多样化测试。我们在27个开源Python项目上的实验结果表明,TELPA显著优于最先进的SBST和基于LLM的技术,在分支覆盖率方面平均提升了31.39%和22.22%。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。