While recent advances in large language models (LLMs) have shown promise in automating test generation for regression testing, they often suffer from limited reasoning about program execution, resulting in stagnated coverage growth - a phenomenon known as the coverage plateau. This paper presents TestWeaver, a novel LLM-based approach that integrates lightweight program analysis to create a focused execution context that assists LLMs in better test generation. TestWeaver strategically chooses the following components to overcome LLMs' limited reasoning on complex execution: (1) it reduces hallucinations and improves focus by supplying the LLM with the backward slice from the target line instead of a full program context; (2) it identifies and incorporates close test cases - those that share control-flow similarities with the path to the target line - to provide focused execution context within the LLM's context window; and (3) it enhances LLM's reasoning with execution in-line annotations that encode variable states as comments along the executed path. By equipping LLMs with these targeted and contextualized inputs, it improves coverage-guided test generation and mitigates redundant explorations. Empirical results show that TestWeaver accelerates code coverage growth and generates more effective test cases than the state-of-the-art approaches.


翻译:尽管大语言模型(LLMs)在自动化回归测试生成方面展现出潜力,但其通常对程序执行过程的推理能力有限,导致代码覆盖率增长停滞——这一现象被称为覆盖率平台期。本文提出TestWeaver,一种新颖的基于LLM的方法,该方法通过集成轻量级程序分析来创建聚焦的执行上下文,以辅助LLM生成更有效的测试用例。TestWeaver通过以下策略性组件来克服LLM对复杂执行逻辑的推理局限:(1)通过向LLM提供目标代码行的后向切片而非完整程序上下文,减少幻觉并提升关注度;(2)识别并整合相近测试用例——即与目标行路径具有控制流相似性的测试用例——以在LLM上下文窗口内提供聚焦的执行上下文;(3)通过内联执行注释(将变量状态以注释形式编码在已执行路径上)增强LLM的推理能力。通过为LLM提供这些定向且情境化的输入,TestWeaver改进了覆盖率引导的测试生成,并减少了冗余探索。实证结果表明,与现有最先进方法相比,TestWeaver能加速代码覆盖率的增长,并生成更有效的测试用例。

0
下载
关闭预览

相关内容

评估大语言模型在科学发现中的作用
专知会员服务
19+阅读 · 2025年12月19日
大语言模型中的检索与结构化增强生成综述
专知会员服务
32+阅读 · 2025年9月17日
什么是后训练?大语言模型训练后优化方法综述,87页pdf
定制化大型语言模型的图检索增强生成综述
专知会员服务
37+阅读 · 2025年1月28日
《大型语言模型代码生成》综述
专知会员服务
68+阅读 · 2024年6月4日
大型语言模型在预测和异常检测中的应用综述
专知会员服务
70+阅读 · 2024年2月19日
推荐|上交大推出Texygen:文本生成模型的基准测试平台
国家自然科学基金
4+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
VIP会员
相关VIP内容
评估大语言模型在科学发现中的作用
专知会员服务
19+阅读 · 2025年12月19日
大语言模型中的检索与结构化增强生成综述
专知会员服务
32+阅读 · 2025年9月17日
什么是后训练?大语言模型训练后优化方法综述,87页pdf
定制化大型语言模型的图检索增强生成综述
专知会员服务
37+阅读 · 2025年1月28日
《大型语言模型代码生成》综述
专知会员服务
68+阅读 · 2024年6月4日
大型语言模型在预测和异常检测中的应用综述
专知会员服务
70+阅读 · 2024年2月19日
相关基金
国家自然科学基金
4+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员