arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2502.02708cs.SE
收藏

AsserT5:使用微调的代码语言模型生成测试断言

AsserT5: Test Assertion Generation Using a Fine-Tuned Code Language Model

Severin Primbs, Benedikt Fein, Gordon Fraser

AI总结:

本文提出基于预训练CodeT5微调的AsserT5模型生成测试断言,发现抽象标识符与包含焦点方法能显著提升精确度至59.5%,但在Defects4J真实漏洞检测中效果有限,仅找出33个漏洞。

摘要:

编写良好的软件测试可能具有挑战性,因此支持开发人员的方法是可取的。虽然自动生成完整测试是研究中常提出的一种方法,但开发人员可能已经想到了特定的测试场景,因此只需要帮助为这些场景选择最合适的测试断言。这可以通过使用深度学习模型为给定的测试代码预测断言来实现。先前关于断言生成的研究专门针对该任务训练这些模型,这引发了一个问题:使用此后出现的在代码上预训练的更大模型能在多大程度上提高其性能。特别是,虽然抽象标识符已被证明可以改进专门训练的模型,但这是否也适用于在非抽象代码上预训练的模型仍不清楚。最后,尽管先前的工作展示了高准确率,但尚不清楚这如何转化为断言在其预期应用——发现故障——中的有效性。为了阐明这些悬而未决的问题,在本文中,我们提出了 AsserT5,一种基于预训练 CodeT5 模型的新模型,并使用它来实证研究断言生成。我们发现,抽象和包含焦点方法对微调的预训练模型也很有用,生成的测试断言在高达 59.5% 的情况下与真实断言完全匹配,精确度是先前模型的两倍多。然而,对 Defects4J 数据集中真实漏洞的评估表明,在现实世界项目中可使用断言检测的 138 个漏洞中,AsserT5 仅能为其中 33 个漏洞建议发现故障的断言,这表明需要进一步改进。

英文摘要:

Writing good software tests can be challenging, therefore approaches that support developers are desirable. While generating complete tests automatically is such an approach commonly proposed in research, developers may already have specific test scenarios in mind and thus just require help in selecting the most suitable test assertions for these scenarios. This can be done using deep learning models to predict assertions for given test code. Prior research on assertion generation trained these models specifically for the task, raising the question how much the use of larger models pre-trained on code that have emerged since then can improve their performance. In particular, while abstracting identifiers has been shown to improve specifically trained models, it remains unclear whether this also generalises to models pre-trained on non-abstracted code. Finally, even though prior work demonstrated high accuracy it remains unclear how this translates into the effectiveness of the assertions at their intended application -- finding faults. To shed light on these open questions, in this paper we propose AsserT5, a new model based on the pre-trained CodeT5 model, and use this to empirically study assertion generation. We find that the abstraction and the inclusion of the focal method are useful also for a fine-tuned pre-trained model, resulting in test assertions that match the ground truth assertions precisely in up to 59.5\% of cases, more than twice as precise as prior models. However, evaluation on real bugs from the Defects4J dataset shows that out of 138 bugs detectable with assertions in real-world projects, AsserT5 was only able to suggest fault-finding assertions for 33, indicating the need for further improvements.

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

↑