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

CasModaTest:一种用于单元测试生成的级联式且模型无关的自导向框架

CasModaTest: A Cascaded and Model-agnostic Self-directed Framework for Unit Test Generation

Chao Ni, Xiaoya Wang, Liushan Chen, Dehai Zhao, Zhengong Cai, Shaohua Wang, Xiaohu Yang

AI总结:

针对现有基于ML的单元测试生成方法存在的生成内容不全、语义不匹配、绑定闭源模型等问题,提出级联模型无关框架CasModaTest,结合示例池与错误修复机制,在Defects4J数据集及多款开源LLM上均大幅优于SOTA方法。

摘要:

尽管已有许多基于机器学习(ML)的单元测试生成方法被提出,且确实取得了显著性能,但它们在有效性和实际使用中仍存在若干局限。更具体地说,现有基于ML的方法存在三大问题:(1)仅生成单元测试的部分内容,主要聚焦于测试预言(test oracle)生成;(2)测试前缀与测试预言在语义上不匹配;(3)与闭源模型高度绑定,最终会损害数据安全。\n我们提出CasModaTest——一种级联、模型无关的端到端单元测试生成框架,通过两个级联阶段缓解上述局限:测试前缀生成和测试预言生成。随后,我们人工构建了大规模示例池,为CasModaTest提供高质量的测试前缀和测试预言样例。最后,CasModaTest会自动组装生成的测试前缀与测试预言,通过编译或执行验证其有效性,还可选择性地进行多次尝试,以修复编译和执行阶段出现的错误。\n为评估CasModaTest的有效性,我们在广泛使用的数据集Defects4J上开展了大规模实验,选取两项性能指标,将其与四种当前最优(SOTA)方法进行对比。实验结果表明,CasModaTest的表现大幅优于所有SOTA方法:准确率提升60.62%-352.55%,核心方法覆盖率提升2.83%-87.27%。此外,我们还在不同的开源大语言模型(LLM)上测试了CasModaTest,发现在端到端单元测试生成任务中,CasModaTest同样能相较SOTA方法取得显著提升,准确率和核心方法覆盖率的提升幅度分别为39.82%-293.96%和9.25%-98.95%。

英文摘要:

Though many machine learning (ML)-based unit testing generation approaches have been proposed and indeed achieved remarkable performance, they still have several limitations in effectiveness and practical usage. More precisely, existing ML-based approaches (1) generate partial content of a unit test, mainly focusing on test oracle generation; (2) mismatch the test prefix with the test oracle semantically; and (3) are highly bound with the close-sourced model, eventually damaging data security. We propose CasModaTest, a cascaded, model-agnostic, and end-to-end unit test generation framework, to alleviate the above limitations with two cascaded stages: test prefix generation and test oracle generation. Then, we manually build large-scale demo pools to provide CasModaTest with high-quality test prefixes and test oracles examples. Finally, CasModaTest automatically assembles the generated test prefixes and test oracles and compiles or executes them to check their effectiveness, optionally appending with several attempts to fix the errors occurring in compiling and executing phases. To evaluate the effectiveness of CasModaTest, we conduct large-scale experiments on a widely used dataset (Defects4J) and compare it with four state-of-the-art (SOTA) approaches by considering two performance measures. The experimental results indicate that CasModaTest outperforms all SOTAs with a substantial improvement (i.e., 60.62%-352.55% in terms of accuracy, 2.83%-87.27% in terms of focal method coverage). Besides, we also conduct experiments of CasModaTest on different open-source LLMs and find that CasModaTest can also achieve significant improvements over SOTAs (39.82%-293.96% and 9.25%-98.95% in terms of accuracy and focal method coverage, respectively) in end-to-end unit test generation

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

↑