一句话:提出基于 LLM 的 TestUpdater,在代码变更时自动修复并增强单元测试,并构建了 Updates4J 基准。
单元测试对软件质量至关重要,但人工维护效率低且易遗漏。现有自动化测试维护方法主要修复破损测试,忽略了增强既有测试以验证新功能的场景;同时其依赖规则化的上下文收集且缺乏验证机制,难以应对复杂代码变更,生成用例正确率低。本文提出 TestUpdater,一种基于大语言模型(LLM)的即时测试更新方法:它先模拟开发者的推理过程,用 LLM 分析代码变更并识别相关上下文,再抽取与过滤,从而灵活获得准确充分的上下文;随后通过精心设计的提示逐步处理各类代码变更与新引入依赖,同时支持破损测试修复与测试增强;最后模拟调试过程,引入错误类型感知的迭代精化机制,执行更新后的测试并修复失败。为评估测试增强场景,作者构建了包含 7 个项目、195 个真实样本的 Updates4J 基准。实验表明,TestUpdater 编译通过率达 94.4%、测试通过率 86.7%,分别比最先进的 Synter 高出 15.9% 和 20.0%,分支覆盖率与行覆盖率也分别高出 12.9% 和 15.2%。
Unit testing is critical for ensuring software quality and software system stability. The current practice of manually maintaining unit tests suffers from low efficiency and the risk of delayed or overlooked fixes. Therefore, an automated approach is required to instantly update unit tests, with the capability to both repair and enhance unit tests. However, existing automated test maintenance methods primarily focus on repairing broken tests, neglecting the scenario of enhancing existing tests to verify new functionality. Meanwhile, due to their reliance on rule-based context collection and the lack of verification mechanisms, existing approaches struggle to handle complex code changes and often produce test cases with low correctness.To address these challenges, we propose TestUpdater, a novel Large Language Model (LLM) based approach that enables automated just-in-time test updates in response to production code changes. By emulating the reasoning process of developers, TestUpdater first leverages the LLM to analyze code changes and identify relevant context, which it then extracts and filters. This LLM-driven context collector can flexibly gather accurate and sufficient context, enabling better handling of complex code changes. Then, through carefully designed prompts, TestUpdater guides the LLM step by step to handle various types of code changes and introduce new dependencies, enabling both the repair of broken tests and the enhancement of tests. Finally, emulating the debugging process, we introduce an error-type-aware iterative refinement mechanism that executes the LLM-updated tests and repairs failures, which significantly improves the overall correctness of test updates.Since existing test repair datasets lack scenarios of test enhancement, we further construct a new benchmark, Updates4J, with 195 real-world samples from 7 projects, enabling execution-based evaluation of test updates. Experimental results show that TestUpdater achieves a compilation pass rate of 94.4% and a test pass rate of 86.7%, outperforming the state-of-the-art method Synter by 15.9% and 20.0%, respectively. Furthermore, TestUpdater exhibits 12.9% higher branch coverage and 15.2% greater line coverage than Synter.
DOI 原文 ·
@inproceedings{paperbot9443,
title = {Unit Test Update through LLM-Driven Context Collection and Error-Type-Aware Refinement},
author = {Yuanhe Zhang and Zhiquan Yang and Shengyi Pan and Zhongxin Liu},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00206}
}