Automated Detection and Refactoring of Mock Clones in Java Projects

Mocking is an essential technique in unit testing, allowing developers to isolate dependencies for more focused and reliable tests. However, repetitive patterns of mock creation, termed mock clones, introduce significant redundancy, increasing maintenance costs, reducing readability, and complicating updates in test code. To address these challenges, our research investigates the detection and refactoring of mock clones, aiming to improve the maintainability and efficiency of test code in large software projects. We began with an empirical study of mocking framework usage across open-source Java projects, revealing widespread adoption of frameworks like Mockito, along with patterns and practices that commonly lead to mock clones. Following this, we analyzed the prevalence and impact of mock clones across six representative projects, identifying significant redundancy and demonstrating the limitations of traditional clone detection tools. Manual refactoring of identified mock clones reduced thousands of redundant lines, with developers responding positively to these improvements. Building on these foundational studies, our ongoing work seeks to develop automated tools for detecting and refactoring mock clones, enabling systematic and scalable improvements to test code. This research offers both empirical insights and practical solutions that contribute toward automated test code maintenance, advancing sustainable software testing practices.

Authors

Institutions

Publication Details

Published
2025-04-27
DOI
https://doi.org/10.1109/icse-companion66252.2025.00035
Citations
2
Primary Topic
Software Engineering Research
Type
article
Field-Weighted Citation Impact
6.49

Funders

Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Automated Detection and Refactoring of Mock Clones in Java Projects

Gengwu Zhao
2 citations
Software Engineering Research
6.49
article

Automated Detection and Refactoring of Mock Clones in Java Projects

Gengwu Zhao
article en
2 citations

Abstract

Mocking is an essential technique in unit testing, allowing developers to isolate dependencies for more focused and reliable tests. However, repetitive patterns of mock creation, termed mock clones, introduce significant redundancy, increasing maintenance costs, reducing readability, and complicating updates in test code. To address these challenges, our research investigates the detection and refactoring of mock clones, aiming to improve the maintainability and efficiency of test code in large software projects. We began with an empirical study of mocking framework usage across open-source Java projects, revealing widespread adoption of frameworks like Mockito, along with patterns and practices that commonly lead to mock clones. Following this, we analyzed the prevalence and impact of mock clones across six representative projects, identifying significant redundancy and demonstrating the limitations of traditional clone detection tools. Manual refactoring of identified mock clones reduced thousands of redundant lines, with developers responding positively to these improvements. Building on these foundational studies, our ongoing work seeks to develop automated tools for detecting and refactoring mock clones, enabling systematic and scalable improvements to test code. This research offers both empirical insights and practical solutions that contribute toward automated test code maintenance, advancing sustainable software testing practices.

Stevens Institute of Technology (US)
National Science Foundation
Openalex Percentile: Top 4%
Software Engineering Research
6.49
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.