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

基于缺陷报告的测试用例自动生成:一项大语言模型可行性研究

Automatic Generation of Test Cases based on Bug Reports: a Feasibility Study with Large Language Models

Laura Plein, Wendkûuni C. Ouédraogo, Jacques Klein, Tegawendé F. Bissyandé

AI总结:

本研究针对现有自动测试生成方法的局限性,探索利用大语言模型以缺陷报告为输入生成复杂场景测试用例的可行性,实验验证了其效果及在故障定位、补丁验证等任务中的实用价值。

摘要:

软件测试是软件工程的核心学科,该领域已产出大量研究成果,尤其是在自动测试生成方向。由于现有方法生成的测试用例要么属于简单类型(例如单元测试),要么需要精确的规约,大多数测试流程仍依赖人工编写的测试用例来构建测试套件。然而这类测试套件存在不完备性:它们仅覆盖项目的部分内容,或是在缺陷修复后才生成。但自动程序修复等多项研究挑战以及从业者的工作流程,都建立在可用测试套件足够充分的假设之上。因此有必要打破自动测试用例生成的现有壁垒。\n此前的研究主要聚焦于随机单元测试输入,而我们提出生成能够真实反映复杂用户执行场景的测试用例,这类场景可暴露缺陷行为。此类场景在缺陷报告中以非形式化方式描述,因此缺陷报告应被视为指定缺陷触发测试用例的天然输入。本研究中,我们探究了利用大语言模型(LLM)、以缺陷报告为输入完成该生成任务的可行性。我们的实验既使用了在线服务ChatGPT,也用到了CodeGPT——一种针对代码领域预训练、并为我们的任务做了微调的LLM。\n总体而言,我们通过实验证明,与Defects4J数据集中至多50%缺陷相关的缺陷报告,能够引导ChatGPT生成可执行测试用例。我们证实即便是全新的缺陷报告,确实也可作为输入生成可执行测试用例。最后我们报告的实验结果确认,LLM生成的测试用例可直接用于软件工程任务,例如故障定位以及自动程序修复中的补丁验证。

英文摘要:

Software testing is a core discipline in software engineering where a large array of research results has been produced, notably in the area of automatic test generation. Because existing approaches produce test cases that either can be qualified as simple (e.g. unit tests) or that require precise specifications, most testing procedures still rely on test cases written by humans to form test suites. Such test suites, however, are incomplete: they only cover parts of the project or they are produced after the bug is fixed. Yet, several research challenges, such as automatic program repair, and practitioner processes, build on the assumption that available test suites are sufficient. There is thus a need to break existing barriers in automatic test case generation. While prior work largely focused on random unit testing inputs, we propose to consider generating test cases that realistically represent complex user execution scenarios, which reveal buggy behaviour. Such scenarios are informally described in bug reports, which should therefore be considered as natural inputs for specifying bug-triggering test cases. In this work, we investigate the feasibility of performing this generation by leveraging large language models (LLMs) and using bug reports as inputs. Our experiments include the use of ChatGPT, as an online service, as well as CodeGPT, a code-related pre-trained LLM that was fine-tuned for our task. Overall, we experimentally show that bug reports associated to up to 50% of Defects4J bugs can prompt ChatGPT to generate an executable test case. We show that even new bug reports can indeed be used as input for generating executable test cases. Finally, we report experimental results which confirm that LLM-generated test cases are immediately useful in software engineering tasks such as fault localization as well as patch validation in automated program repair.

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

↑