arXiv:2510.01994cs.SEcs.AI2025-10中稿 · the research track…被引 7

用程序分析与大模型重写,提升测试用例语义清晰度。

Clarifying Semantics of In-Context Examples for Unit Test Generation

  • 分解复杂测试并结合程序分析与大模型重写,增强语义清晰度。
  • 保持原测试有效性,同时使用户更偏好其表达清晰度。
  • 显著提升基于上下文学习的测试生成效果,适合测试自动化研究者。

大语言模型通过上下文学习在单元测试生成中表现优异,但上下文示例的质量直接影响生成效果——结构不良或语义模糊的示例常导致次优结果。本文提出CLAST,一种系统性优化单元测试语义清晰度的新方法,通过将复杂测试分解为逻辑更清晰的版本,并结合程序分析与大模型重写实现改进。我们在四个开源项目和三个工业项目上评估了CLAST,结果表明其显著优于当前最优的修正技术UTgen:CLAST完全保留原始测试的有效性,而UTgen使编译成功率(CSR)、通过率(PR)、测试覆盖率(Cov)和突变分数(MS)平均下降12.90%、35.82%、4.65%和5.07%。用户研究中超过85.33%的参与者更偏好CLAST优化后的测试。将CLAST优化的测试作为示例,可使RAGGen和TELPA等基于上下文学习的生成方法在测试生成上平均提升25.97%的CSR、28.22%的PR和45.99%的Cov。

原文摘要 · Abstract (English)

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.

测试生成大模型代码理解程序分析

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。