通过自我调试合成文件级数据用于单元测试生成的链式思考
Synthesizing File-Level Data for Unit Test Generation with Chain-of-Thoughts via Self-Debugging
AI总结:
通过自我调试合成文件级数据用于单元测试生成,提升测试生成质量与准确性。
摘要:
自动单元测试(UT)生成对于软件质量保证至关重要,但现有的方法,包括符号执行、基于搜索的方法以及最近的基于大语言模型(LLM)的生成器,难以生成具有正确、有意义断言和可靠链式思考(CoT)解释的人类质量测试。我们发现UT训练数据存在一个缺口:仓库挖掘的测试缺乏开发者CoTs,而LLM压缩的CoTs往往不正确或不完整。为了解决这个问题,我们提出了一种新的数据压缩方法,利用自我调试来生成高质量的UT训练示例并配以忠实的CoTs。我们的方法结合(1)引导测试修复,一个启发式循环(以错误、失败和覆盖为中心的步骤),要求使用的模型诊断并迭代修复生成的测试,以及(2)CoT压缩,将原始和调试CoTs压缩成简洁的解释,直接证明正确的测试。我们将此流程应用于大量开源项目的大数据集,构建了包含74,518个高质量<焦点方法,测试,CoT>示例的数据集,然后使用它对基础模型进行监督微调。实证评估显示,微调后的模型在UT生成效果上表现优异:其在测试断言上的通过率达到了36.17%,分支覆盖率为43.90%,突变得分为88.66%,显著高于最先进的商业模型如o4-mini。
英文摘要:
Automatic unit test (UT) generation is essential for software quality assurance, but existing approaches--including symbolic execution, search-based approaches, and recent LLM-based generators--struggle to produce human-quality tests with correct, meaningful assertions and reliable chain-of-thought (CoT) explanations. We identify a gap in UT training data: repository-mined tests lack developer CoTs, while LLM-distilled CoTs are often incorrect or incomplete. To address this issue, we propose a novel data-distillation approach that uses self-debugging to produce high-quality UT training examples paired with faithful CoTs. Our approach combines (1) guided test repair, a heuristic loop (error-, failure-, and coverage-focused steps) that asks the used model to diagnose and iteratively fix generated tests, and (2) CoT compression, which compacts original and debugging CoTs into concise explanations that directly justify correct tests. We apply this pipeline to a large corpus of open-source projects to construct a dataset of 74,518 high-quality <focal method, test, CoT> examples, and then use it for supervised fine-tuning of a base model. An empirical evaluation shows that the fine-tuned model achieves high UT generation effectiveness: it attains a pass rate of 36.17% on test assertions, a branch coverage of 43.90%, and a mutation score of 88.66%, substantially higher than state-of-the-art commercial models like o4-mini.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。