澄清单元测试生成中上下文示例的语义
Clarifying Semantics of In-Context Examples for Unit Test Generation
AI总结:
针对大语言模型上下文学习生成单元测试时示例语义不清导致效果不佳的问题,提出结合程序分析与LLM重写的CLAST技术,可在保留测试有效性的同时提升示例语义清晰度,显著优化多种ICL测试生成方法的性能。
摘要:
大语言模型(LLM)的最新进展通过上下文学习(ICL)在单元测试生成中取得了可观的性能。然而,上下文示例的质量会显著影响生成测试的有效性——结构不佳或语义不清晰的测试示例往往会导致输出效果欠佳。本文提出了CLAST(澄清语义测试)这一新技术,它能系统性地优化单元测试以提升其语义清晰度,从而增强其作为上下文示例的实用性。该方法将复杂测试分解为逻辑更清晰的测试,并结合程序分析与基于LLM的重写来提升语义清晰度。我们在4个开源项目和3个工业项目上评估了CLAST。结果表明,CLAST在保留测试有效性和提升语义清晰度两方面均大幅优于当前最先进的优化技术UTgen。具体而言,CLAST完全保留了单元测试的原有有效性,而UTgen使编译成功率(CSR)、通过率(PR)、测试覆盖率(Cov)和变异得分(MS)分别平均下降了12.90%、35.82%、4.65%和5.07%。在我们的用户研究中,超过85.33%的参与者更偏好CLAST优化后测试的语义清晰度。值得注意的是,将CLAST优化后的测试作为示例,能有效改进基于ICL的单元测试生成方法(如RAGGen和TELPA),与使用UTgen优化后的测试相比,生成测试的CSR平均提升25.97%,PR平均提升28.22%,Cov平均提升45.99%。后续用户研究的结论不仅印证了CLAST在软件测试实践中的潜在影响力,也为未来研究指明了方向。
英文摘要:
Recent advances in large language models (LLMs) have enabled promising performance in unit test generation through in-context learning (ICL). However, the quality of in-context examples significantly influences the effectiveness of generated tests-poorly structured or semantically unclear test examples often lead to suboptimal outputs. In this paper, we propose CLAST, a novel technique that systematically refines unit tests to improve their semantic clarity, thereby enhancing their utility as in-context examples. The approach decomposes complex tests into logically clearer ones and improves semantic clarity through a combination of program analysis and LLM-based rewriting. We evaluated CLAST on four open-source and three industrial projects. The results demonstrate that CLAST largely outperforms UTgen, the state-of-the-art refinement technique, in both preserving test effectiveness and enhancing semantic clarity. Specifically, CLAST fully retains the original effectiveness of unit tests, while UTgen reduces compilation success rate (CSR), pass rate (PR), test coverage (Cov), and mutation score (MS) by an average of 12.90%, 35.82%, 4.65%, and 5.07%, respectively. Over 85.33% of participants in our user study preferred the semantic clarity of CLAST-refined tests. Notably, incorporating CLAST-refined tests as examples effectively improves ICL-based unit test generation approaches such as RAGGen and TELPA, resulting in an average increase of 25.97% in CSR, 28.22% in PR, and 45.99% in Cov for generated tests, compared to incorporating UTgen-refined tests. The insights from the follow-up user study not only reinforce CLAST's potential impact in software testing practice but also illuminate avenues for future research.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。