论文标题

在学习单位测试案例的有意义的断言陈述时

On Learning Meaningful Assert Statements for Unit Test Cases

论文作者

Watson, Cody, Tufano, Michele, Moran, Kevin, Bavota, Gabriele, Poshyvanyk, Denys

论文摘要

软件测试是软件生命周期的重要组成部分,需要大量的时间和精力。据估计,软件开发人员将近50%的时间用于测试他们编写的代码。由于这些原因,研究社区内的长期目标是(部分)自动化软件测试。尽管已经提出了几种技术和工具来自动生成测试方法,但最近的工作批评了它们生成的断言语句的质量和实用性。因此,我们采用基于神经机器翻译(NMT)的方法称为ATLAS(自动学习断言语句),以自动为测试方法生成有意义的断言语句。给定测试方法和焦点方法(即,正在测试的主要方法),地图集可以预测有意义的断言陈述,以评估焦点方法的正确性。我们将Atlas应用于GitHub项目的数千种测试方法,并能够预测开发人员在31%的情况下手动编写的确定声明,仅考虑了TOP-1预测的断言。在考虑前5个预测的声明声明时,Atlas能够预测50%的情况下的确切匹配。这些有希望的结果暗示了(i)对自动测试案例生成技术的补充,以及(ii)为开发人员提供代码完成支持,惠坎在编写测试代码时从推荐的断言语句中受益。

Software testing is an essential part of the software lifecycle and requires a substantial amount of time and effort. It has been estimated that software developers spend close to 50% of their time on testing the code they write. For these reasons, a long standing goal within the research community is to (partially) automate software testing. While several techniques and tools have been proposed to automatically generate test methods, recent work has criticized the quality and usefulness of the assert statements they generate. Therefore, we employ a Neural Machine Translation (NMT) based approach called Atlas(AuTomatic Learning of Assert Statements) to automatically generate meaningful assert statements for test methods. Given a test method and a focal method (i.e.,the main method under test), Atlas can predict a meaningful assert statement to assess the correctness of the focal method. We applied Atlas to thousands of test methods from GitHub projects and it was able to predict the exact assert statement manually written by developers in 31% of the cases when only considering the top-1 predicted assert. When considering the top-5 predicted assert statements, Atlas is able to predict exact matches in 50% of the cases. These promising results hint to the potential usefulness ofour approach as (i) a complement to automatic test case generation techniques, and (ii) a code completion support for developers, whocan benefit from the recommended assert statements while writing test code.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源