[论文解读] Large Language Models are Few-shot Testers: Exploring LLM-based General Bug Reproduction
本文提出 Libro 框架,利用大型语言模型(LLMs)从 Java 项目中的自然语言错误报告自动生成测试用例。通过后处理 LLM 输出并应用验证启发式规则,Libro 在 Defects4J 案例中成功重现了 33.5% 的错误,并在 149 个错误中将有效重现测试作为首选结果,展现出显著降低开发者测试创建工作量的潜力。
Many automated test generation techniques have been developed to aid developers with writing tests. To facilitate full automation, most existing techniques aim to either increase coverage, or generate exploratory inputs. However, existing test generation techniques largely fall short of achieving more semantic objectives, such as generating tests to reproduce a given bug report. Reproducing bugs is nonetheless important, as our empirical study shows that the number of tests added in open source repositories due to issues was about 28% of the corresponding project test suite size. Meanwhile, due to the difficulties of transforming the expected program semantics in bug reports into test oracles, existing failure reproduction techniques tend to deal exclusively with program crashes, a small subset of all bug reports. To automate test generation from general bug reports, we propose LIBRO, a framework that uses Large Language Models (LLMs), which have been shown to be capable of performing code-related tasks. Since LLMs themselves cannot execute the target buggy code, we focus on post-processing steps that help us discern when LLMs are effective, and rank the produced tests according to their validity. Our evaluation of LIBRO shows that, on the widely studied Defects4J benchmark, LIBRO can generate failure reproducing test cases for 33% of all studied cases (251 out of 750), while suggesting a bug reproducing test in first place for 149 bugs. To mitigate data contamination, we also evaluate LIBRO against 31 bug reports submitted after the collection of the LLM training data terminated: LIBRO produces bug reproducing tests for 32% of the studied bug reports. Overall, our results show LIBRO has the potential to significantly enhance developer efficiency by automatically generating tests from bug reports.
研究动机与目标
- 探究直接从自然语言错误报告使用 LLM 生成测试用例的可行性,该任务在自动化测试领域尚属未充分探索的领域。
- 解决为非崩溃型错误生成语义上有意义测试的挑战,现有技术常因“测试 oracle 问题”而忽略此类错误。
- 开发一个不仅可生成潜在测试用例,还能对其进行排序和验证的框架,以确保可靠性并减轻开发者的认知负担。
- 通过在 LLM 预训练数据中未见的后期训练错误报告上进行测试,评估该方法对数据泄露的鲁棒性。
提出的方法
- Libro 以少样本提示方式,向 Codex LLM 输入错误报告和源代码,生成候选测试用例。
- 通过后处理启发式规则对生成的测试输出进行过滤和验证,依据语法正确性、编译成功与否以及执行行为进行判断。
- 通过评估编译成功、运行时异常和测试执行结果等指标,衡量测试重现报告失败的可能性,对生成的测试进行排序。
- 结合静态分析与动态执行,验证生成的测试是否真正重现了错误,从而区分有效与无效的尝试。
- 在 Defects4J 基准和新收集的真实世界报告-测试数据集上评估系统,以衡量其泛化能力和鲁棒性。
- 为减轻数据泄露风险,方法在 31 个后期训练错误报告上进行评估,确保结果并非源于记忆化。
实验结果
研究问题
- RQ1LLM 是否能有效从自然语言错误报告中生成测试用例,而无需依赖基于崩溃的 oracle?
- RQ2像 Libro 这类框架在多个 LLM 生成的输出中,能否准确识别并排序出最具前景的测试候选?
- RQ3Libro 在未出现在 LLM 训练数据中的真实世界后期训练错误报告上,其泛化能力如何?
- RQ4哪些错误报告和测试用例的关键特征会导致基于 LLM 的生成方法成功重现错误?
主要发现
- Libro 在 750 个 Defects4J 错误中的 251 个(33.5%)成功重现了导致失败的测试用例,展现出在广泛使用基准上的强劲性能。
- 在其中 149 个错误中,Libro 将有效且能重现失败的测试作为首个建议,显著降低了开发者在测试选择上的工作量。
- 在新收集的真实世界数据集(31 个后期训练错误报告)上的独立评估中,Libro 成功重现了 32.2% 的错误,表明其在训练数据之外具有良好的泛化能力。
- 该框架在正确识别实际能重现错误的生成测试方面达到 71.4% 的准确率,表明其在测试排序方面具有较强的可靠性。
- 该方法在需要外部文件或非标准测试基础设施的错误上表现较差,凸显了当前在处理复杂测试依赖方面的局限性。
- 仅有三个案例显示出可能从报告中记忆了测试代码的迹象,表明结果中数据污染程度极低。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。