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

仅通过测试代码可以对不稳定测试进行分类吗?基于LLM的经验研究

Can We Classify Flaky Tests Using Only Test Code? An LLM-Based Empirical Study

Heidelberg University(海德堡大学);University of Mannheim(曼海姆大学);SAP(思爱普)

Alexander Berndt, Vekil Bekmyradov, Rainer Gemulla, Marcus Kessel, Thomas Bach, Sebastian Baltes

AI总结:

本研究探讨了仅通过测试代码是否能有效分类不稳定测试,发现LLM在无额外上下文时表现有限,需进一步结合检索增强生成等方法提升泛化能力。

摘要:

不稳定测试在相同代码修订上反复执行时会产生不一致的结果。它们干扰了代码变更的自动化质量保证,并阻碍了高效的软件测试。先前的工作评估了训练机器学习模型以根据测试代码中的标识符来分类不稳定测试的方法。然而,所得到的分类器已被证明缺乏泛化能力,阻碍了其在实际环境中的应用。最近,预训练的大型语言模型(LLMs)展示了在各种任务上泛化的能力。因此,它们代表了解决先前方法泛化问题的有希望的方法。在本研究中,我们使用三种LLM(两种通用模型,一个代码特定模型)和三种提示技术,在两个先前研究中的基准数据集上进行了评估。此外,我们手动调查了来自给定数据集的50个样本,以确定仅基于测试代码分类不稳定测试对人类是否可行。我们的发现表明,LLM在仅给定测试代码的情况下难以分类不稳定测试。我们最佳提示-模型组合的结果仅略微优于随机猜测。在我们的手动分析中,我们发现测试代码并不一定包含足够的信息用于分类不稳定性。我们的发现促使未来的工作评估LLM用于不稳定性分类时,使用额外的上下文,例如使用检索增强生成或代理AI。

英文摘要:

Flaky tests yield inconsistent results when they are repeatedly executed on the same code revision. They interfere with automated quality assurance of code changes and hinder efficient software testing. Previous work evaluated approaches to train machine learning models to classify flaky tests based on identifiers in the test code. However, the resulting classifiers have been shown to lack generalizability, hindering their applicability in practical environments. Recently, pre-trained Large Language Models (LLMs) have shown the capability to generalize across various tasks. Thus, they represent a promising approach to address the generalizability problem of previous approaches. In this study, we evaluated three LLMs (two general-purpose models, one code-specific model) using three prompting techniques on two benchmark datasets from prior studies on flaky test classification. Furthermore, we manually investigated 50 samples from the given datasets to determine whether classifying flaky tests based only on test code is feasible for humans. Our findings indicate that LLMs struggle to classify flaky tests given only the test code. The results of our best prompt-model combination were only marginally better than random guessing. In our manual analysis, we found that the test code does not necessarily contain sufficient information for a flakiness classification. Our findings motivate future work to evaluate LLMs for flakiness classification with additional context, for example, using retrieval-augmented generation or agentic AI.

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

↑