TY - GEN
T1 - Mock Clones in the Wild
T2 - 32nd Asia-Pacific Software Engineering Conference, APSEC 2025
AU - Zhao, Gengwu
AU - Xiao, Lu
AU - Qin, Hanbin
AU - Alomar, Eman Abdullah
AU - Wong, Sunny
N1 - Publisher Copyright:
© 2025 IEEE.
PY - 2025
Y1 - 2025
N2 - Background: Mocking is a common technique for isolating test dependencies, yet duplicated mock setup code-what we call "mock clones"-can increase test maintenance overhead and reduce clarity. While code clone detection is a mature research area, the prevalence, characteristics, and refactoring of mock clones remain insufficiently understood. Aims: This study investigates the prevalence, detection challenges, and practical elimination of mock clones in real-world Java test suites, aiming to identify systematic patterns and assess the feasibility and value of mock clone refactoring. Method: We analyzed 698 mock clone instances across six open-source Java projects. We evaluated the effectiveness of existing code clone detection tools in capturing mock clones, manually refactored a large subset of clones to assess behavior preservation, and measured the structural impact of mock clone elimination. Results: Mock clones are prevalent, with frequently mocked classes often exhibiting extensive duplication. Existing clone detection tools failed to reliably detect mock clones due to scattered, reordered, and semantically varied mocking logic. Manual refactoring successfully eliminated 60% of identified mock clones while preserving test behavior, resulting in up to 64% reduction in mock objects and up to 61% reduction in mocking-related LOC. Targeting only the top 5 10 high-impact clones still achieved substantial simplification. Conclusions: Mock clone elimination is both feasible and highly valuable for improving test code maintainability. Systematic refactoring strategies can address common patterns, and prioritizing high-impact clones enables efficient gains with minimal effort. These findings motivate the need for mock-aware detection and automated refactoring tools to unlock broader maintainability improvements in testing practices.
AB - Background: Mocking is a common technique for isolating test dependencies, yet duplicated mock setup code-what we call "mock clones"-can increase test maintenance overhead and reduce clarity. While code clone detection is a mature research area, the prevalence, characteristics, and refactoring of mock clones remain insufficiently understood. Aims: This study investigates the prevalence, detection challenges, and practical elimination of mock clones in real-world Java test suites, aiming to identify systematic patterns and assess the feasibility and value of mock clone refactoring. Method: We analyzed 698 mock clone instances across six open-source Java projects. We evaluated the effectiveness of existing code clone detection tools in capturing mock clones, manually refactored a large subset of clones to assess behavior preservation, and measured the structural impact of mock clone elimination. Results: Mock clones are prevalent, with frequently mocked classes often exhibiting extensive duplication. Existing clone detection tools failed to reliably detect mock clones due to scattered, reordered, and semantically varied mocking logic. Manual refactoring successfully eliminated 60% of identified mock clones while preserving test behavior, resulting in up to 64% reduction in mock objects and up to 61% reduction in mocking-related LOC. Targeting only the top 5 10 high-impact clones still achieved substantial simplification. Conclusions: Mock clone elimination is both feasible and highly valuable for improving test code maintainability. Systematic refactoring strategies can address common patterns, and prioritizing high-impact clones enables efficient gains with minimal effort. These findings motivate the need for mock-aware detection and automated refactoring tools to unlock broader maintainability improvements in testing practices.
KW - n/a
UR - https://www.scopus.com/pages/publications/105035208766
UR - https://www.scopus.com/pages/publications/105035208766#tab=citedBy
U2 - 10.1109/APSEC66846.2025.00046
DO - 10.1109/APSEC66846.2025.00046
M3 - Conference contribution
AN - SCOPUS:105035208766
T3 - Proceedings - Asia-Pacific Software Engineering Conference, APSEC
SP - 395
EP - 406
BT - Proceedings - 2025 32nd Asia-Pacific Software Engineering Conference, APSEC 2025
A2 - Zhang, Tao
A2 - Luo, Xiapu
A2 - Keung, Jacky
A2 - Choi, Eunjong
Y2 - 2 December 2025 through 5 December 2025
ER -