arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2402.00097cs.SEcs.LG
收藏

代码感知提示:一项在回归场景下使用LLM进行覆盖引导测试生成的研究

Code-Aware Prompting: A study of Coverage Guided Test Generation in Regression Setting using LLM

Columbia University(哥伦比亚大学);AWS AI Labs(亚马逊云科技人工智能实验室)

Gabriel Ryan, Siddhartha Jain, Mingyue Shang, Shiqi Wang, Xiaofei Ma, Murali Krishna Ramanathan, Baishakhi Ray

AI总结:

本文提出代码感知提示策略SymPrompt,通过将测试生成解构为与执行路径对齐的多阶段提示过程,在不额外训练的情况下显著提升LLM的测试覆盖率。

摘要:

测试在确保软件质量方面发挥着关键作用,然而传统的基于搜索的软件测试(SBST)方法在处理复杂软件单元时往往力不从心,难以达到理想的测试覆盖率。近期使用大语言模型(LLMs)进行测试生成的工作侧重于通过优化测试生成上下文和纠正模型输出中的错误来提升生成质量,但采用的是固定的提示策略,仅提示模型生成测试而缺乏额外引导。因此,LLM生成的测试套件仍然存在覆盖率低的问题。在本文中,我们提出了SymPrompt,一种面向LLM测试生成的代码感知提示策略。SymPrompt的方法基于近期的一项研究,该研究表明当LLM被提示以多步骤方式对问题进行推理时,能够解决更复杂的逻辑问题。我们将这一方法论应用于测试生成,通过将测试套件生成过程解构为多阶段序列,每个阶段由与被测方法执行路径对齐的特定提示驱动,并向模型暴露相关的类型和依赖焦点上下文。我们的方法使预训练LLM能够在无需任何额外训练的情况下生成更完整的测试用例。我们使用TreeSitter解析框架实现了SymPrompt,并在一个包含来自开源Python项目且具有挑战性方法的基准上进行了评估。对于CodeGen2,SymPrompt将正确测试生成的数量提升了5倍,并将相对覆盖率提高了26%。值得注意的是,当应用于GPT-4时,与基线提示策略相比,SymPrompt将覆盖率提升了超过2倍。

英文摘要:

Testing plays a pivotal role in ensuring software quality, yet conventional Search Based Software Testing (SBST) methods often struggle with complex software units, achieving suboptimal test coverage. Recent works using large language models (LLMs) for test generation have focused on improving generation quality through optimizing the test generation context and correcting errors in model outputs, but use fixed prompting strategies that prompt the model to generate tests without additional guidance. As a result LLM-generated testsuites still suffer from low coverage. In this paper, we present SymPrompt, a code-aware prompting strategy for LLMs in test generation. SymPrompt's approach is based on recent work that demonstrates LLMs can solve more complex logical problems when prompted to reason about the problem in a multi-step fashion. We apply this methodology to test generation by deconstructing the testsuite generation process into a multi-stage sequence, each of which is driven by a specific prompt aligned with the execution paths of the method under test, and exposing relevant type and dependency focal context to the model. Our approach enables pretrained LLMs to generate more complete test cases without any additional training. We implement SymPrompt using the TreeSitter parsing framework and evaluate on a benchmark challenging methods from open source Python projects. SymPrompt enhances correct test generations by a factor of 5 and bolsters relative coverage by 26% for CodeGen2. Notably, when applied to GPT-4, SymPrompt improves coverage by over 2x compared to baseline prompting strategies.

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

↑