No More Manual Tests? Evaluating and Improving ChatGPT for Unit Test Generation

05/07/2023
by   Zhiqiang Yuan, et al.
0

Unit testing is essential in detecting bugs in functionally-discrete program units. Manually writing high-quality unit tests is time-consuming and laborious. Although traditional techniques can generate tests with reasonable coverage, they exhibit low readability and cannot be directly adopted by developers. Recent work has shown the large potential of large language models (LLMs) in unit test generation, which can generate more human-like and meaningful test code. ChatGPT, the latest LLM incorporating instruction tuning and reinforcement learning, has performed well in various domains. However, It remains unclear how effective ChatGPT is in unit test generation. In this work, we perform the first empirical study to evaluate ChatGPT's capability of unit test generation. Specifically, we conduct a quantitative analysis and a user study to systematically investigate the quality of its generated tests regarding the correctness, sufficiency, readability, and usability. The tests generated by ChatGPT still suffer from correctness issues, including diverse compilation errors and execution failures. Still, the passing tests generated by ChatGPT resemble manually-written tests by achieving comparable coverage, readability, and even sometimes developers' preference. Our findings indicate that generating unit tests with ChatGPT could be very promising if the correctness of its generated tests could be further improved. Inspired by our findings above, we propose ChatTESTER, a novel ChatGPT-based unit test generation approach, which leverages ChatGPT itself to improve the quality of its generated tests. ChatTESTER incorporates an initial test generator and an iterative test refiner. Our evaluation demonstrates the effectiveness of ChatTESTER by generating 34.3 more tests with correct assertions than the default ChatGPT.

READ FULL TEXT

page 1

page 8

research
04/30/2023

Exploring the Effectiveness of Large Language Models in Generating Unit Tests

A code generation model generates code by taking a prompt from a code co...
research
05/08/2023

ChatUniTest: a ChatGPT-based automated unit test generation tool

Unit testing is a crucial, yet often tedious and time-consuming task. To...
research
02/13/2023

Adaptive Test Generation Using a Large Language Model

Unit tests play a key role in ensuring the correctness of software. Howe...
research
06/04/2019

Bridging the Gap between Unit Test Generation and System Test Generation

Common test generators fall into two categories. Generating test inputs ...
research
07/11/2023

Tests4Py: A Benchmark for System Testing

Benchmarks are among the main drivers of progress in software engineerin...
research
08/28/2018

Does the Testing Level affect the Prevalence of Coincidental Correctness?

Researchers have previously shown that Coincidental Correctness (CC) is ...
research
08/02/2023

Manual Tests Do Smell! Cataloging and Identifying Natural Language Test Smells

Background: Test smells indicate potential problems in the design and im...

Please sign up or login with your details

Forgot password? Click here to reset