Recently, deep learning-based test case generation approaches have been proposed to automate the generation of unit test cases. In this study, we leverage Transformer-based code models to generate unit tests with the help of Domain Adaptation (DA) at a project level. Specifically, we use CodeT5, a relatively small language model trained on source code data, and fine-tune it on the test generation task. Then, we apply domain adaptation to each target project data to learn project-specific knowledge (project-level DA). We use the Methods2test dataset to fine-tune CodeT5 for the test generation task and the Defects4j dataset for project-level domain adaptation and evaluation. We compare our approach with (a) CodeT5 fine-tuned on the test generation without DA, (b) the A3Test tool, and (c) GPT-4 on five projects from the Defects4j dataset. The results show that tests generated using DA can increase the line coverage by 18.62%, 19.88%, and 18.02% and mutation score by 16.45%, 16.01%, and 12.99% compared to the above (a), (b), and (c) baselines, respectively. The overall results show consistent improvements in metrics such as parse rate, compile rate, BLEU, and CodeBLEU. In addition, we show that our approach can be seen as a complementary solution alongside existing search-based test generation tools such as EvoSuite, to increase the overall coverage and mutation scores with an average of 34.42% and 6.8%, for line coverage and mutation score, respectively.
Exploring Data-Efficient Adaptation of Large Language Models for Code Generation
Key Laboratory of High Confidence Software Technologies (Peking University), Ministry of Education(高可信软件技术重点实验室(北京大学));School of Computer Science, Peking University, Beijing(计算机学院(北京大学))
Commenting Higher-level Code Unit: Full Code, Reduced Code, or Hierarchical Code Summarization
Nanyang Technological University(南洋理工大学);Yangzhou University(扬州大学);Nanjing University(南京大学);Chongqing University of Posts and Telecommunications(重庆邮电大学);Nanjing Tech University(南京工业大学);Wuhan University(武汉大学);Peking University(北京大学)
Wired for Reuse: Automating Context-Aware Code Adaptation in IDEs via LLM-Based Agent
School of Computer Science and Technology, Beijing Institute of Technology(北京理工大学计算机科学与技术学院);College of Intelligence and Computing, Tianjin University(天津大学智能与计算学部)