在大语言模型支持下进行类聊天式的断言预测
Chat-like Asserts Prediction with the Support of Large Language Model
AI总结:
本文提出基于大语言模型的\ ool方法,利用角色设定、思维链和单样本学习,结合LLM与Python解释器多轮通信,为Python项目生成有意义的断言语句,准确率优于现有方法,有助于推动自动化单元测试发展。
摘要:
单元测试是软件测试的重要组成部分,其中断言语句在判定被测函数是否按预期运行方面发挥着关键作用。尽管已有研究探索了自动化测试用例生成,但生成有意义的断言语句仍是一项持续的挑战。虽然已有若干研究调查了Java中的断言语句生成,但在像Python这样流行的动态类型编程语言中,针对该任务的研究仍然有限。本文提出了基于执行的类聊天断言预测(\ ool),这是一种新颖的基于大语言模型的方法,用于为Python项目生成有意义的断言语句。\ ool在提示词设计中利用了角色设定、思维链和单样本学习技术,并与LLM和Python解释器进行多轮通信以生成有意义的断言语句。我们还展示了一个从GitHub挖掘的Python断言语句数据集。我们的评估表明,\ ool在单个断言语句生成上达到了64.7%的准确率,在整体断言语句生成上达到了62%的准确率,优于现有方法。我们还分析了不匹配的断言语句,这些语句可能仍具有相同的功能,并讨论了\ ool可能为自动化Python单元测试生成提供的潜在帮助。研究结果表明,\ ool有望通过更实际的使用场景来造福软件工程(SE)社区。
英文摘要:
Unit testing is an essential component of software testing, with the assert statements playing an important role in determining whether the tested function operates as expected. Although research has explored automated test case generation, generating meaningful assert statements remains an ongoing challenge. While several studies have investigated assert statement generation in Java, limited work addresses this task in popular dynamically-typed programming languages like Python. In this paper, we introduce Chat-like execution-based Asserts Prediction (\tool), a novel Large Language Model-based approach for generating meaningful assert statements for Python projects. \tool utilizes the persona, Chain-of-Thought, and one-shot learning techniques in the prompt design, and conducts rounds of communication with LLM and Python interpreter to generate meaningful assert statements. We also present a Python assert statement dataset mined from GitHub. Our evaluation demonstrates that \tool achieves 64.7\% accuracy for single assert statement generation and 62\% for overall assert statement generation, outperforming the existing approaches. We also analyze the mismatched assert statements, which may still share the same functionality and discuss the potential help \tool could offer to the automated Python unit test generation. The findings indicate that \tool has the potential to benefit the SE community through more practical usage scenarios.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。