When Testing Meets Refactoring: Catalogue, Detection, and Recommendation
Abstract
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.