Generating Accurate Assert Statements for Unit Test Cases using Pretrained Transformers
arXiv:2009.05634 · doi:10.1145/3524481.3527220
Abstract
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% of the cases in the first attempt. The results show 80% relative improvement for top-1 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.
References in corpus (6)
- Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer
- XLNet: Generalized Autoregressive Pretraining for Language Understanding
- CodeSearchNet Challenge: Evaluating the State of Semantic Code Search
- Pythia: AI-assisted Code Completion System
- On Learning Meaningful Assert Statements for Unit Test Cases
- Automatic Test Improvement with DSpot: a Study with Ten Mature Open-Source Projects
Cited by in corpus (13)
- TOGA: A Neural Method for Test Oracle Generation
- Deep Learning-based Software Engineering: Progress, Challenges, and Opportunities
- Generative AI for Self-Adaptive Systems: State of the Art and Research Roadmap
- Neural-Based Test Oracle Generation: A Large-scale Evaluation and Lessons Learned
- Perfect is the enemy of test oracle
- TOGLL: Correct and Strong Test Oracle Generation with LLMs
- Assessing Evaluation Metrics for Neural Test Oracle Generation
- Large Language Models for Automated Web-Form-Test Generation: An Empirical Study
- AsserT5: Test Assertion Generation Using a Fine-Tuned Code Language Model
- Mokav: Execution-driven Differential Testing with LLMs
- B4: Towards Optimal Assessment of Plausible Code Solutions with Plausible Tests
- Embedding Code Contexts for Cryptographic API Suggestion:New Methodologies and Comparisons
- Long-Range Modeling of Source Code Files with eWASH: Extended Window Access by Syntax Hierarchy