一句话:构建统一的测试重构模式目录与检测工具,并在 170 万个 Java 项目上生成真值基准数据集。
测试代码同样会腐化,需要重构维护,但测试特有的代码异味虽有理论记载,针对测试重构的自动化检测与推荐仍处起步阶段,知识分散、工具不足。本文采用混合方法(仓库挖掘、开发者调查与 StackOverflow 讨论分析)整理出统一的测试重构模式目录,并据此扩展 RefactoringMiner 加入测试感知检测,提出 PatternTracker 在版本历史中追踪测试模式演化。基于该基础设施分析 170 万个 Java 项目,生成高置信度的测试重构真值数据集,验证模式在开源项目中的普遍性,并为评估未来自动推荐系统(含大语言模型驱动方法)建立基准。
Automated software testing is critical for modern software development, yet test code itself requires maintenance and refactoring to prevent decay. While theoretical test-specific code smells are well-documented, the practical automation of test refactoring—both detection and recommendation—remains incipient, leading to fragmented knowledge and inadequate tooling. This paper bridges this gap by presenting a unified catalogue of test refactoring patterns derived from a mixed-method approach involving repository mining, developer surveys, and analysis of StackOverflow discussions. To operationalize this catalogue, we extend RefactoringMiner with test-aware detection capabilities and introduce PatternTracker, a tool for identifying and tracking the evolution of test patterns across version history. Leveraging this infrastructure, we analyzed 1.7 million Java projects to generate a high-confidence ground-truth dataset of test refactorings. Our results validate the prevalence of these patterns in open-source projects and establish a rigorous benchmark for evaluating future automated recommendation systems, including those driven by Large Language Models.