arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2307.00012cs.SEcs.AIcs.LG
收藏

FlakyFix: 利用大语言模型预测不稳定测试修复类别与测试代码修复

FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categories and Test Code Repair

School of EECS, University of Ottawa(渥太华大学电子工程与计算机科学学院);York University(约克大学);University of Limerick(利默里克大学)

Sakina Fatima, Hadi Hemmati, Lionel Briand

AI总结:

针对不稳定测试修复支持不足的问题,提出FlakyFix框架,先预测13类测试自身导致的不稳定测试的修复类别,再将该信息加入GPT-3.5 Turbo提示词引导修复,显著提升修复效果,预计51%-83%的修复可通过测试。

摘要:

不稳定测试(flaky test)存在诸多问题,它们在被测软件版本相同的情况下会非确定性地通过或失败,造成混淆并浪费开发精力。尽管已有机器学习模型被用于预测测试不稳定性及其根本原因,但针对该问题修复支持的相关研究仍十分有限。为填补这一空白,本文聚焦于预测消除测试不稳定性所需的修复类型,并在此基础上修复测试代码。我们针对的是一类不稳定测试的子集:其不稳定性的根源在于测试本身,而非生产代码。研究的核心思路之一是,借助测试不稳定性的额外知识(以预测得到的修复类别形式)来引导修复过程。为此,我们首先提出一个框架,该框架可自动生成包含13种修复类别的标注数据集,并仅通过分析测试代码训练模型,以预测不稳定测试的修复类别。我们使用代码模型和少样本学习开展的实验结果表明,模型能够正确预测大多数修复类别。为证明这类修复类别标签对自动修复测试不稳定性的实用性,我们将此类额外知识加入大语言模型(LLM)GPT-3.5 Turbo的提示词中,以请求生成修复建议。结果显示,我们提出的修复类别标签结合上下文学习,显著提升了GPT-3.5 Turbo生成不稳定测试修复方案的能力。基于对GPT修复的不稳定测试样本的执行与分析,我们估计这类修复中有很大比例(约51%至83%)有望通过测试。对于修复后仍失败的测试,平均需要进一步修改16%的测试代码才能使其通过。

英文摘要:

Flaky tests are problematic because they non-deterministically pass or fail for the same software version under test, causing confusion and wasting development effort. While machine learning models have been used to predict flakiness and its root causes, there is much less work on providing support to fix the problem. To address this gap, in this paper, we focus on predicting the type of fix that is required to remove flakiness and then repair the test code on that basis. We do this for a subset of flaky tests where the root cause of flakiness is in the test itself and not in the production code. One key idea is to guide the repair process with additional knowledge about the test's flakiness in the form of its predicted fix category. Thus, we first propose a framework that automatically generates labeled datasets for 13 fix categories and trains models to predict the fix category of a flaky test by analyzing the test code only. Our experimental results using code models and few-shot learning show that we can correctly predict most of the fix categories. To show the usefulness of such fix category labels for automatically repairing flakiness, we augment the prompts of GPT-3.5 Turbo, a Large Language Model (LLM), with such extra knowledge to request repair suggestions. The results show that our suggested fix category labels, complemented with in-context learning, significantly enhance the capability of GPT-3.5 Turbo in generating fixes for flaky tests. Based on the execution and analysis of a sample of GPT-repaired flaky tests, we estimate that a large percentage of such repairs (roughly between 51% and 83%) can be expected to pass. For the failing repaired tests, on average, 16% of the test code needs to be further changed for them to pass.

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

↑