一句话:用 CodeT5 微调并做项目级领域自适应,提升单元测试生成覆盖率与变异得分。
论文研究如何用深度学习自动生成单元测试。作者以在源码上预训练的 CodeT5 为基础,先在 Methods2test 数据集上微调测试生成任务,再针对每个目标项目进行项目级领域自适应,以学习项目特定知识。在 Defects4j 的五个项目上,与未做领域自适应的 CodeT5、A3Test 和 GPT-4 比较,生成测试的行覆盖率分别提升 18.62%、19.88%、18.02%,变异得分提升 16.45%、16.01%、12.99%;解析率、编译率、BLEU 和 CodeBLEU 也整体改善。该方法还可与 EvoSuite 等搜索式测试生成工具互补,平均提升行覆盖率 34.42%、变异得分 6.8%。
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.
DOI 原文 ·
@inproceedings{paperbot8593,
title = {Domain Adaptation for Code Model-Based Unit Test Case Generation},
author = {Jiho Shin and Sepehr Hashtroudi and Hadi Hemmati and Song Wang},
booktitle = {ISSTA},
year = {2024},
doi = {10.1145/3650212.3680354}
}