Search-based test generators are effective at producing unit tests with high coverage. However, such automatically generated tests have no meaningful test and variable names, making them hard to understand and interpret by developers. On the other hand, large language models (LLMs) can generate highly readable test cases, but they are not able to match the effectiveness of search-based generators, in terms of achieved code coverage.
In this paper, we propose to combine the effectiveness of search-based generators with the readability of LLM generated tests. Our approach focuses on improving test and variable names produced by search-based tools, while keeping their semantics (i.e., their coverage) unchanged.
Our evaluation on nine industrial and open source LLMs show that our readability improvement transformations are overall semantically-preserving and stable across multiple repetitions. Moreover, a human study with ten professional developers, show that our LLM-improved tests are as readable as developer-written tests, regardless of the LLM employed.
Towards the Readability of LLM-Generated Codes through Multitask Representation Engineering
School of Aerospace Engineering, Xiamen University(厦门大学航空航天工程学院);School of Artificial Intelligence, Shenzhen University(深圳大学人工智能学院);College of Computer and Cyber Security, Fujian Normal University(福建师范大学计算机与网络安全部分);Department of Computer & Information Sciences, Northumbria University(北爱尔兰北安普顿大学计算机与信息科学系);School of Computer Science and Technology, Xidian University(西安电子科技大学计算机科学与技术学院);Peking University(北京大学)
Humanizing Automatically Generated Unit Test Suites with LLM-Based Refactoring
University of Luxembourg(卢森堡大学);Nanjing University of Science and Technology(南京理工大学);Zhejiang University(浙江大学);Bilkent University(比尔肯特大学);Singapore Management University(新加坡管理大学)