On Learning Meaningful Assert Statements for Unit Test Cases

被引:93
作者
Watson, Cody [1 ]
Tufano, Michele [2 ]
Moran, Kevin [3 ]
Bavota, Gabriele [4 ]
Poshyvanyk, Denys [3 ]
机构
[1] Washington & Lee Univ, Lexington, VA 24450 USA
[2] Microsoft, Washington, DC USA
[3] William & Mary, Williamsburg, VA USA
[4] Univ Svizzera Italiana USI, Lugano, Switzerland
来源
2020 ACM/IEEE 42ND INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE 2020) | 2020年
基金
瑞士国家科学基金会;
关键词
D O I
10.1145/3377811.3380429
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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 of our approach as (i) a complement to automatic test case generation techniques, and (ii) a code completion support for developers, who can benefit from the recommended assert statements while writing test code.
引用
收藏
页码:1398 / 1409
页数:12
相关论文
共 37 条
[1]   An Industrial Evaluation of Unit Test Generation: Finding Real Faults in a Financial Application [J].
Almasi, M. Moein ;
Hemmati, Hadi ;
Fraser, Gordon ;
Arcuri, Andrea ;
Benefelds, Janis .
2017 IEEE/ACM 39TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING: SOFTWARE ENGINEERING IN PRACTICE TRACK (ICSE-SEIP 2017), 2017, :263-272
[2]   Migrating Code with Statistical Machine Translation [J].
Anh Tuan Nguyen ;
Tung Thanh Nguyen ;
Nguyen, Tien N. .
36TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE COMPANION 2014), 2014, :544-547
[3]  
[Anonymous], Utilizing fast testing to transform java development into an agile, quick release, low risk process
[4]  
[Anonymous], 2019, Atlas anonymous online appendix
[5]  
[Anonymous], TIOBE INDEX AUGUST 2
[6]  
[Anonymous], APACHE MAVEN
[7]  
[Anonymous], 2019, CHRIS THUNES
[8]  
Chen Z, 2019, Sequencer: Sequence-to-sequence learning for end-to-end program repair
[9]  
Cohn M, 2009, Succeeding with agile: software development using Scrum
[10]  
Di Penta Massimiliano, 2018, ABS181210772 CORR