arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2308.08033cs.SEcs.AI
收藏

基于代码模型的单元测试用例生成的领域自适应

Domain Adaptation for Code Model-based Unit Test Case Generation

York University(约克大学);University of Calgary(卡尔加里大学)

Jiho Shin, Sepehr Hashtroudi, Hadi Hemmati, Song Wang

AI总结:

本文提出在项目级别对CodeT5进行领域自适应以生成单元测试,并在Defects4j上验证其相比无DA的CodeT5、A3Test和GPT-4显著提升行覆盖率与变异分数,且可与EvoSuite互补。

摘要:

近年来,基于深度学习的测试用例生成方法被提出,以自动化单元测试用例的生成。在本研究中,我们利用基于Transformer的代码模型,在项目级别借助领域自适应(Domain Adaptation, DA)来生成单元测试。具体而言,我们使用CodeT5——一个在源代码数据上训练的规模相对较小的语言模型,并在测试生成任务上对其进行微调。然后,我们对每个目标项目数据应用领域自适应,以学习项目特定的知识(项目级DA)。我们使用Methods2test数据集对CodeT5进行测试生成任务的微调,并使用Defects4j数据集进行项目级领域自适应和评估。我们将我们的方法与以下基线在Defects4j数据集的五个项目上进行比较:(a)在测试生成任务上微调但未使用DA的CodeT5,(b)A3Test工具,以及(c)GPT-4。结果表明,与上述(a)、(b)和(c)基线相比,使用DA生成的测试分别可以将行覆盖率提高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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑