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

LLM 生成的测试预言捕获的是实际程序行为还是预期程序行为?

Can we find bugs using LLM-generated oracles?

University of Luxembourg(卢森堡大学);Luxembourg Institute of Science and Technology(卢森堡科学与技术研究所)

Michael Konstantinou, Renzo Degiovanni, Mike Papadakis

AI总结:

针对 24 个 Java 仓库的受控实验表明,LLM 生成的测试预言仍倾向反映程序实际行为,但其生成能力强于分类能力且故障检测潜力优于 Evosuite。

摘要:

软件测试是软件开发生命周期中提升代码质量的重要组成部分。通常,单元测试由测试前缀和测试预言组成,测试预言用于捕获开发者预期的行为。传统测试生成技术(例如 Randoop 和 Evosuite)的一个已知局限是,它们生成的测试预言捕获的是程序的实际行为,而非预期行为。近期方法利用在海量数据上训练的大型语言模型(LLM)来生成类似开发者编写的代码和测试用例。我们研究 LLM 生成的测试预言捕获的是实际还是预期的软件行为。为此,我们开展了一项受控实验,通过研究 LLM 在测试预言分类和生成两项任务上的表现来回答该问题。研究涵盖来自 24 个开源 Java 仓库的开发者编写及自动生成的测试用例和预言,并使用了多种经过充分测试的提示词。研究结果表明,基于 LLM 的测试生成方法同样倾向于生成捕获程序实际行为而非预期行为的预言。此外,LLM 更擅长生成测试预言,而不是分类正确的预言;当代码包含有意义的测试或变量名称时,它们能够生成更好的测试预言。最后,LLM 生成的测试预言比 Evosuite 生成的预言具有更高的故障检测潜力。

英文摘要:

Unit testing is vital in software development. Typically, a unit test consists of a test prefix and a test oracle which captures the developer's intended behaviour. Traditional test generation tools (e.g. Randoop and Evosuite) often produce oracles that mirror the program's actual behavior rather than the expected one, limiting their ability to automatically detect bugs as users must manually verify if the generated assertions are correct. Recent approaches leverage Large Language Models (LLMs), trained on vast datasets, to generate developer-like code and test cases. Although successful in generating tests, the question of whether such LLM-generated oracles can automatically find bugs, i.e., expected software behavior, remains unanswered. We conduct a controlled experiment to answer this question, by studying LLMs on two tasks, namely, test oracle classification and generation, and assessing whether LLM oracles capture the actual or the expected behavior. The study includes test cases and oracles written by developers and automatically generated for 24 Java repositories. Our findings show that LLM-based test generation approaches mainly capture the actual program behavior making bug detection difficult. We also find that LLMs are better at generating oracles than classifying them. Notably, LLM-generated oracles have a higher fault detection potential than the Evosuite ones.

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

↑