On Learning Meaningful Assert Statements for Unit Test Cases

By Cody Watson, Michele Tufano, Kevin Moran, Gabriele Bavota, Denys Poshyvanyk. 2020

196 citations recorded by the source corpus.

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.

Subfields: Information Systems, Software, Code Generation & Program Synthesis

How researchers see this paper

The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.

In Information Systems

  1. Georgios Gousios
  2. Neel Sundaresan
  3. Michael Pradel
  4. Alexey Svyatkovskiy
  5. Satish Chandra
  6. Shao Kun Deng
  7. Sarah Nadi
  8. Jason Liu

In Software

  1. Neel Sundaresan
  2. Michael Pradel
  3. Alexey Svyatkovskiy
  4. Georgios Gousios
  5. Armando Solar-Lezama
  6. Shao Kun Deng
  7. Sarah Nadi
  8. Frank Tip

In Code Generation & Program Synthesis

  1. Georgios Gousios
  2. Michael Pradel
  3. Koushik Sen
  4. Sarah Nadi
  5. Satish Chandra
  6. Armando Solar-Lezama
  7. Neel Sundaresan
  8. Shao Kun Deng

Citations in the corpus