arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2511.06227cs.SEcs.AIcs.CE
收藏

基于断言感知的大语言模型测试代码摘要生成

Assertion-Aware Test Code Summarization with Large Language Models

University of North Texas(北卡罗来纳州立大学)

Anamul Haque Mollah, Ahmed Aljohani, Hyunsook Do

AI总结:

本文构建了91个Java测试用例基准,通过消融实验发现基于断言语义的提示能以更少token提升LLM测试摘要质量,并评估了四种代码LLM的性能。

摘要:

单元测试往往缺乏能够传达测试意图的简洁摘要,尤其是在自动生成或文档不完善的代码库中。大语言模型(LLMs)提供了一种有前景的解决方案,但其有效性在很大程度上取决于提示方式。与通用代码摘要不同,测试代码摘要面临独特的挑战,因为测试方法通过断言来验证预期行为,而不是实现功能。本文提出了一个由91个真实世界Java测试用例组成的新基准,并配以开发者撰写的摘要,同时开展了一项受控消融研究,以探究测试代码相关组件——如被测方法(MUT)、断言消息和断言语义——如何影响LLM生成的测试摘要的性能。我们使用n-gram指标(BLEU、ROUGE-L、METEOR)、语义相似度(BERTScore)以及基于LLM的评估,在七种提示配置下评估了四个代码LLM(Codex、Codestral、DeepSeek和Qwen-Coder)。结果表明,使用断言语义进行提示相比完整MUT上下文,摘要质量平均提高了0.10分(2.3%)(4.45对4.35),同时所需的输入token更少。Codex和Qwen-Coder与人工撰写的摘要达到了最高的一致性,而DeepSeek尽管词汇重叠度较高,但表现不佳。复现包已在https://doi.org/10.5281/zenodo.17067550公开提供。

英文摘要:

Unit tests often lack concise summaries that convey test intent, especially in auto-generated or poorly documented codebases. Large Language Models (LLMs) offer a promising solution, but their effectiveness depends heavily on how they are prompted. Unlike generic code summarization, test-code summarization poses distinct challenges because test methods validate expected behavior through assertions rather than implementing functionality. This paper presents a new benchmark of 91 real-world Java test cases paired with developer-written summaries and conducts a controlled ablation study to investigate how test code-related components-such as the method under test (MUT), assertion messages, and assertion semantics-affect the performance of LLM-generated test summaries. We evaluate four code LLMs (Codex, Codestral, DeepSeek, and Qwen-Coder) across seven prompt configurations using n-gram metrics (BLEU, ROUGE-L, METEOR), semantic similarity (BERTScore), and LLM-based evaluation. Results show that prompting with assertion semantics improves summary quality by an average of 0.10 points (2.3%) over full MUT context (4.45 vs. 4.35) while requiring fewer input tokens. Codex and Qwen-Coder achieve the highest alignment with human-written summaries, while DeepSeek underperforms despite high lexical overlap. The replication package is publicly available at https://doi.org/10. 5281/zenodo.17067550

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

↑