arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.10628cs.SE
收藏

论LLM生成的单元测试中测试异味的扩散

On the Diffusion of Test Smells in LLM-Generated Unit Tests

University of Luxembourg(卢森堡大学);Nanjing University of Science and Technology(南京理工大学);Bilkent University(比尔肯特大学);Singapore Management University(新加坡管理大学)

Wendkûuni C. Ouédraogo, Yinghua Li, Xueqi Dang, Xunzhu Tang, Anil Koyuncu, Jacques Klein, David Lo, Tegawendé F. Bissyandé

AI总结:

本研究通过多基准大规模分析,对比LLM生成、人类编写及EvoSuite生成的单元测试,发现LLM生成测试存在特定测试异味,受提示策略等影响,凸显基于LLM的测试生成的潜力与风险,呼吁开发相关优化方案。

摘要:

大型语言模型(LLM)有望将单元测试生成从手动负担转变为自动化解决方案。然而,除了可编译性或覆盖率等指标外,人们对LLM生成测试的质量知之甚少,尤其是其对测试异味的敏感性——测试异味是指破坏可读性和可维护性的设计缺陷。本文首次开展了针对LLM生成单元测试中测试异味扩散的多基准、大规模分析。我们将LLM输出与人类编写的测试套件(作为现实世界实践的参考)以及EvoSuite生成的SBST测试(作为自动化基准)进行对比,以区分LLM是再现了类似人类的缺陷还是合成生成的产物。本研究基于四个LLM(GPT-3.5、GPT-4、Mistral 7B、Mixtral 8x7B)的20505个类级测试套件、TestBench的972个方法级案例、14469个EvoSuite测试,以及来自34635个开源Java项目的779585个人类编写测试。我们使用两个互补的检测工具(TsDetect和JNose),分析了测试异味的流行程度、共现情况,以及其与软件属性和生成参数的相关性。结果显示,LLM生成的测试始终表现出断言轮盘(Assertion Roulette)和魔法数字测试(Magic Number Test)等异味,且模式受提示策略、上下文长度和模型规模的强烈影响。对比发现,其与人类编写的测试存在重叠,引发了对训练语料库潜在数据泄露的担忧,而EvoSuite则表现出独特的、特定于生成器的缺陷。这些发现凸显了基于LLM的测试生成的潜力与风险,并呼吁设计感知异味的生成框架、提示工程策略以及增强的检测工具,以确保测试代码具备可维护性和高质量。

英文摘要:

LLMs promise to transform unit test generation from a manual burden into an automated solution. Yet, beyond metrics such as compilability or coverage, little is known about the quality of LLM-generated tests, particularly their susceptibility to test smells, design flaws that undermine readability and maintainability. This paper presents the first multi-benchmark, large-scale analysis of test smell diffusion in LLM-generated unit tests. We contrast LLM outputs with human-written suites (as the reference for real-world practices) and SBST-generated tests from EvoSuite (as the automated baseline), disentangling whether LLMs reproduce human-like flaws or artifacts of synthetic generation. Our study draws on 20,505 class-level suites from four LLMs (GPT-3.5, GPT-4, Mistral 7B, Mixtral 8x7B), 972 method-level cases from TestBench, 14,469 EvoSuite tests, and 779,585 human-written tests from 34,635 open-source Java projects. Using two complementary detection tools (TsDetect and JNose), we analyze prevalence, co-occurrence, and correlations with software attributes and generation parameters. Results show that LLM-generated tests consistently manifest smells such as Assertion Roulette and Magic Number Test, with patterns strongly influenced by prompting strategy, context length, and model scale. Comparisons reveal overlaps with human-written tests, raising concerns of potential data leakage from training corpora while EvoSuite exhibits distinct, generator-specific flaws. These findings highlight both the promise and the risks of LLM-based test generation, and call for the design of smell-aware generation frameworks, prompt engineering strategies, and enhanced detection tools to ensure maintainable, high-quality test code.

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

↑