Generating Accurate Assert Statements for Unit Test Cases using Pretrained Transformers

09/11/2020
by   Michele Tufano, et al.
0

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 in the first attempt. The results show 80 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.

READ FULL TEXT
research
09/11/2020

Unit Test Case Generation with Transformers

Automated Unit Test Case generation has been the focus of extensive lite...
research
02/13/2020

On Learning Meaningful Assert Statements for Unit Test Cases

Software testing is an essential part of the software lifecycle andrequi...
research
10/26/2021

Automated Support for Unit Test Generation: A Tutorial Book Chapter

Unit testing is a stage of testing where the smallest segment of code th...
research
11/12/2018

A Fine-Grained Approach for Automated Conversion of JUnit Assertions to English

Converting source or unit test code to English has been shown to improve...
research
05/11/2020

A Pattern-based Approach to Detect and Improve Non-descriptive Test Names

Unit tests are an important artifact that supports the software developm...
research
02/20/2023

Learning Deep Semantics for Test Completion

Writing tests is a time-consuming yet essential task during software dev...
research
11/18/2019

Combining Program Analysis and Statistical Language Model for Code Statement Completion

Automatic code completion helps improve developers' productivity in thei...

Please sign up or login with your details

Forgot password? Click here to reset