Generating meaningful assert statements is one of the key challenges in automated test case generation, which requires understanding the intended functionality of the tested code. Recently, deep learning-based models have shown promise in improving the performance of assert statement generation. However, existing models only rely on the test prefixes along with their corresponding focal methods, yet ignore the developer-written summarization. Based on our observations, the summarization contents usually express the intended program behavior or contain parameters that will appear directly in the assert statement. Such information will help existing models address their current inability to accurately predict assert statements. This paper presents a novel summarization-guided approach for automatically generating assert statements. To derive generic representations for natural language (i.e., summarization) and programming language (i.e., test prefixes and focal methods), we leverage a pre-trained language model as the reference architecture and fine-tune it on the task of assert statement generation. To the best of our knowledge, the proposed approach makes the first attempt to leverage the summarization of focal methods as the guidance for making the generated assert statements more accurate. We demonstrate the effectiveness of our approach on two real-world datasets when compared with state-of-the-art models.
翻译:摘要:生成有意义的断言语句是自动化测试用例生成的关键挑战之一,这要求理解被测试代码的预期功能。近年来,基于深度学习的模型在提升断言语句生成性能方面展现出潜力。然而,现有模型仅依赖测试前缀及其对应的焦点方法,却忽略了开发者编写的代码摘要。根据我们的观察,摘要内容通常表述了预期的程序行为,或包含将直接出现在断言语句中的参数。这些信息有助于现有模型克服当前无法准确预测断言语句的局限性。本文提出了一种新颖的基于摘要引导的断言语句自动生成方法。为导出自然语言(即摘要)与编程语言(即测试前缀和焦点方法)的通用表征,我们采用预训练语言模型作为参考架构,并针对断言语句生成任务对其进行微调。据我们所知,所提方法首次尝试利用焦点方法的摘要作为引导,使生成的断言语句更加准确。通过在两个真实世界数据集上的实验,我们证明了该方法相较于当前最先进模型的有效性。