Skip to main navigation Skip to search Skip to main content

Mock Clones in the Wild: An Empirical Investigation Across Six Open-Source Projects

  • Stevens Institute of Technology

Research output: Chapter in Book/Report/Conference proceedingConference contributionpeer-review

Abstract

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.

Original languageEnglish
Title of host publicationProceedings - 2025 32nd Asia-Pacific Software Engineering Conference, APSEC 2025
EditorsTao Zhang, Xiapu Luo, Jacky Keung, Eunjong Choi
Pages395-406
Number of pages12
ISBN (Electronic)9798331566531
DOIs
StatePublished - 2025
Event32nd Asia-Pacific Software Engineering Conference, APSEC 2025 - Macau, China
Duration: 2 Dec 20255 Dec 2025

Publication series

NameProceedings - Asia-Pacific Software Engineering Conference, APSEC
ISSN (Print)1530-1362

Conference

Conference32nd Asia-Pacific Software Engineering Conference, APSEC 2025
Country/TerritoryChina
CityMacau
Period2/12/255/12/25

Keywords

  • n/a

Fingerprint

Dive into the research topics of 'Mock Clones in the Wild: An Empirical Investigation Across Six Open-Source Projects'. Together they form a unique fingerprint.

Cite this