arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.03625cs.SE
收藏

修复测试:利用静态收集器和神经重排序器增强LLM修复测试用例

Fix the Tests: Augmenting LLMs to Repair Test Cases with Static Collector and Neural Reranker

Jun Liu, Jiwei Yan, Yuanyuan Xie, Jun Yan, Jian Zhang

AI总结:

针对测试代码与生产代码不同步导致的过时测试修复问题,提出SYNTER方法,通过静态分析收集三类上下文并用神经重排序器筛选,输入LLM修复测试,实验显示优于基线且幻觉减少57.1%。

摘要:

在软件演化过程中,测试代码应与生产代码共同演化。在真实开发场景中,测试更新可能滞后于生产代码变更,这可能导致编译失败或带来其他问题。现有的基于预训练语言模型的技术可以直接用于修复由这种不同步代码变更导致的过时测试,尤其是与语法相关的测试。然而,缺乏面向任务的上下文信息影响了大型项目上的修复准确性。从一个过时的测试开始,关键挑战性任务是在有限的token大小内,从整个代码库中精确识别和构建面向测试修复的上下文(TROCtxs)。在本文中,我们提出了SYNTER(语法破坏性变更引发的测试修复),一种基于LLM的新方法,通过精确且简洁的TROCtxs构建来自动修复过时的测试用例。受开发者编程实践的启发,我们设计了三种类型的TROCtx:类上下文、使用上下文和环境上下文。给定一个待修复的过时测试用例,SYNTER首先通过静态分析技术自动收集每种TROCtx类型的相关代码信息。然后,它生成重排序查询以识别最相关的TROCtxs,这些TROCtxs将被视为修复所需的关键上下文,并输入到大型语言模型中进行最终的测试修复。为了评估SYNTER的有效性,我们构建了一个基准数据集,其中包含一组由语法破坏性变更导致的过时测试。实验结果表明,SYNTER在文本匹配和意图匹配指标上均优于基线方法。通过增强构建的TROCtxs,幻觉减少了57.1%。

英文摘要:

During software evolution, it is advocated that test code should co-evolve with production code. In real development scenarios, test updating may lag behind production code changing, which may cause compilation failure or bring other troubles. Existing techniques based on pre-trained language models can be directly adopted to repair obsolete tests caused by such unsynchronized code changes, especially syntactic-related ones. However, the lack of task-oriented contextual information affects the repair accuracy on large-scale projects. Starting from an obsolete test, the key challenging task is precisely identifying and constructing Test-Repair-Oriented Contexts (TROCtxs) from the whole repository within a limited token size. In this paper, we propose SYNTER (SYNtactic-breaking-changes-induced TEst Repair), a novel approach based on LLMs to automatically repair obsolete test cases via precise and concise TROCtxs construction. Inspired by developers' programming practices, we design three types of TROCtx: class context, usage context, and environment context. Given an obsolete test case to repair, SYNTER firstly collects the related code information for each type of TROCtx through static analysis techniques automatically. Then, it generates reranking queries to identify the most relevant TROCtxs, which will be taken as the repair-required key contexts and be input to the large language model for the final test repair. To evaluate the effectiveness of SYNTER, we construct a benchmark dataset that contains a set of obsolete tests caused by syntactic breaking changes. The experimental results show that SYNTER outperforms baseline approaches both on textual- and intent-matching metrics. With the augmentation of constructed TROCtxs, hallucinations are reduced by 57.1%.

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

↑