arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.14619cs.SEcs.AI
收藏

exLong:利用大型语言模型生成异常行为测试

exLong: Generating Exceptional Behavior Tests with Large Language Models

The University of Texas at Austin(德克萨斯大学奥斯汀分校);University of Waterloo(滑铁卢大学)

Jiyang Zhang, Yu Liu, Pengyu Nie, Junyi Jessy Li, Milos Gligoric

AI总结:

本文提出首个自动生成异常行为测试的框架 exLong,通过基于 CodeLlama 指令微调并嵌入异常相关轨迹与条件推理,在对比实验中优于现有模型和工具,其生成的 23 个测试已被开源项目接受。

摘要:

许多流行的编程语言,包括 C#、Java 和 Python,都支持异常。如果在程序执行期间发生不期望的事件,例如使用非法参数值调用方法,则会抛出异常。软件开发人员编写异常行为测试(EBTs),以检查其代码是否检测到不期望的事件并抛出适当的异常。先前的研究已经表明 EBTs 的重要性,但这些研究也强调,开发人员将大部分精力放在“快乐路径”上,例如没有不期望事件的路径。为了帮助开发人员填补这一空白,我们提出了第一个框架,称为 exLong,它可以自动生成 EBTs。exLong 是一个基于 CodeLlama 进行指令微调的大型语言模型,并嵌入了关于导致 throw 语句的轨迹、保护 throw 语句的条件表达式以及执行相似轨迹的非异常行为测试的推理。我们将 exLong 与最先进的测试生成模型(CAT-LM)和最强的基础模型之一(GPT-4o),以及基于分析的测试生成工具(Randoop 和 EvoSuite)进行了比较。我们的结果表明,exLong 优于现有模型和工具。此外,我们向开源项目贡献了多个拉取请求,其中由 exLong 生成的 23 个 EBTs 已被接受。

英文摘要:

Many popular programming languages, including C#, Java, and Python, support exceptions. Exceptions are thrown during program execution if an unwanted event happens, e.g., a method is invoked with an illegal argument value. Software developers write exceptional behavior tests (EBTs) to check that their code detects unwanted events and throws appropriate exceptions. Prior research studies have shown the importance of EBTs, but those studies also highlighted that developers put most of their efforts on "happy paths", e.g., paths without unwanted events. To help developers fill the gap, we present the first framework, dubbed exLong, that automatically generates EBTs. exLong is a large language model instruction fine-tuned from CodeLlama and embeds reasoning about traces that lead to throw statements, conditional expressions that guard throw statements, and non-exceptional behavior tests that execute similar traces. We compare exLong with the state-of-the-art models for test generation (CAT-LM) and one of the strongest foundation models (GPT-4o), as well as with analysis-based tools for test generation (Randoop and EvoSuite). Our results show that exLong outperforms existing models and tools. Furthermore, we contributed several pull requests to open-source projects and 23 EBTs generated by exLong were already accepted.

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

↑