[论文解读] Can We Classify Flaky Tests Using Only Test Code? An LLM-Based Empirical Study
研究评估大型语言模型是否能仅用测试代码对不稳定测试进行分类,结果显示LLM在此任务上的表现欠佳,MCC 得分弱、非确定性明显,并且在没有额外上下文的情况下 humans 的可行性有限
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.
研究动机与目标
- 评估预训练的LLMs是否仅使用测试代码而不进行任务特定微调即可对不稳定测试进行分类。
- 在基准数据集上评估多种提示策略(零-shot、零-shot 逐步思路、少样本逐步思路)。
- 分析基于LLM的分类结果的确定性,并将其与基于测试代码的不稳定性的人类判断进行比较。
- 为今后在引入额外上下文或检索增强方法方面提供研究建议。
提出的方法
- 在四种提示设置下,以温度=0评估三种LLM(GPT-4o、GPT-OSS-120b、Qwen3-Coder-480b)。
- 使用零-shot、零-shot 逐步思路和少样本逐步思路提示,并给出六条上下文演示(其中三条为 flaky、三条为 non-flaky)。
- 在两个不稳定性基准(IDoFT 子集和 FlakeBench)上进行测试,衡量加权精度、加权召回、加权F1和MCC。
- 通过在每种设置下重复三次,归一化汉明距离来评估非确定性。
- 对来自 IDoFT 的 50 个 flaky 示例进行人工判断研究,评估仅测试代码的分类可行性。
实验结果
研究问题
- RQ1RQ1:在零-shot、零-shot 逐步思路和少样本逐步思路提示下,LLMs 基于测试代码对不稳定测试的分类表现如何?
- RQ2RQ2:在重复运行中,基于LLM的不稳定性分类的非确定性程度有多大?
- RQ3RQ3:人类在仅使用测试代码的情况下对不稳定测试的分类在多大程度上可行?
主要发现
- 在两个数据集上,LLMs 在仅使用测试代码进行不稳定测试分类的表现均较差。
- 在 IDoFT 上,少样本逐步思路下达到的最佳 MCC 为 0.27;在 FlakeBench 上,使用零-shot 提示的 GPT-OSS 最大 MCC 为 0.17。
- 少样本提示通常能提升通用模型在 IDoFT 上的结果,但整体表现仍然薄弱(MCC ≤ 0.27)。
- 观察到显著的非确定性(归一化汉明距离在某些设定下高达 0.25),提高了在生产环境中部署的可靠性担忧。
- Qwen-Code 整体非确定性较低,在某些设定中可在重复运行中得到相同结果。
- 人工分析表明仅靠测试代码不足以识别更复杂的不稳定性类型;某些不稳定性需要超出测试代码的上下文信息。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。