使用预训练的Transformers生成单元测试用例的精确断言语句
Generating Accurate Assert Statements for Unit Test Cases using Pretrained Transformers
摘要:
单元测试代表了软件测试金字塔的基础,位于集成和端到端测试之下。自动化软件测试的研究人员已经提出了各种各样的技术来帮助开发人员完成这项耗时的任务。在本文中,我们提出了一种方法来支持开发人员编写单元测试的情况下,生成准确和有用的断言语句。我们的方法是基于一个国家的最先进的Transformer模型,最初预训练的英语文本语料库。这个语义丰富的模型然后以半监督的方式在大型源代码语料库上进行训练。最后,我们在为单元测试生成断言语句的任务上微调这个模型。生成的模型能够为给定的测试方法生成准确的断言语句。在我们的实证评估中,该模型能够在第一次尝试中预测开发人员在62%的情况下编写的确切断言语句。结果显示,与文献中先前基于RNN的方法相比,top-1准确度相对提高了80%。我们还展示了预训练过程对模型性能的实质性影响,并将其与断言自动完成任务进行了比较。最后,我们展示了我们的方法可以用来增强EvoSuite测试用例,额外的断言导致提高测试覆盖率。
英文摘要:
Unit testing represents the foundational basis of the software testing pyramid, beneath integration and end-to-end testing. Automated software testing researchers have proposed a variety of techniques to assist developers in this time-consuming task. In this paper we present an approach to support developers in writing unit test cases by generating accurate and useful assert statements. Our approach is based on a state-of-the-art transformer model initially pretrained on an English textual corpus. This semantically rich model is then trained in a semi-supervised fashion on a large corpus of source code. Finally, we finetune this model on the task of generating assert statements for unit tests. The resulting model is able to generate accurate assert statements for a given method under test. In our empirical evaluation, the model was able to predict the exact assert statements written by developers in 62% of the cases in the first attempt. The results show 80% relative improvement for top-1 accuracy over the previous RNN-based approach in the literature. We also show the substantial impact of the pretraining process on the performances of our model, as well as comparing it with assert auto-completion task. Finally, we demonstrate how our approach can be used to augment EvoSuite test cases, with additional asserts leading to improved test coverage.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。