An automatic refactoring framework for replacing test-production inheritance by mocking mechanism
Xiao Wang, Lu Xiao, Tingting Yu, Anne Woepse, Sunny Wong
Abstract
Unit testing focuses on verifying the functions of individual units of a software system. It is challenging due to the high inter-dependencies among software units. Developers address this by mocking-replacing the dependency by a "faked" object. Despite the existence of powerful, dedicated mocking frameworks, developers often turn to a "hand-rolled" approach-inheritance. That is, they create a subclass of the dependent class and mock its behavior through method overriding. However, this requires tedious implementation and compromises the design quality of unit tests. This work contributes a fully automated refactoring framework to identify and replace the usage of inheritance by using Mockito-a well received mocking framework. Our approach is built upon the empirical experience from five open source projects that use inheritance for mocking. We evaluate our approach on four other projects. Results show that our framework is efficient, generally applicable to new datasets, mostly preserves test case behaviors in detecting defects (in the form of mutants), and decouples test code from production code. The qualitative evaluation by experienced developers suggests that the auto-refactoring solutions generated by our framework improve the quality of the unit test cases in various aspects, such as making test conditions more explicit, as well as improved cohesion, readability, understandability, and maintainability with test cases.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 6ec3637d-a9d7-4fd0-b38b-2313c0438aa7Cited by top-tier papers4
- Use of Test Doubles in Android Testing: An In-Depth InvestigationMattia Fazzini, Chase Choi, Juan Manuel Copia, Gabriel Lee et al.ICSE 2022 · 19 citations
- A First Look at the Inheritance-Induced Redundant Test ExecutionDong Jae Kim, Jinqiu Yang, Tse-Hsun ChenICSE 2024 · 2 citations
- Fidelity of Cloud Emulators: The Imitation Game of Testing Cloud-Based SoftwareAnna Mazhar, Saad Sher Alam, William X. Zheng, Yinfang Chen et al.ICSE 2025 · 2 citations
- Understanding and Characterizing Mock Assertions in Unit TestsHengcheng Zhu, Valerio Terragni, Lili Wei, Shing-Chi Cheung et al.FSE 2025 · 1 citation
Related papers
- MockSniffer: Characterizing and Recommending Mocking Decisions for Unit TestsHengcheng Zhu, Lili Wei, Ming Wen, Yepang Liu et al.ASE 2020 · 17 citations
- Studying Test Annotation Maintenance in the WildDong Jae Kim, Nikolaos Tsantalis, Tse-Hsun Peter Chen, Jinqiu YangICSE 2021 · 20 citations
- Mock Deep Testing: Toward Separate Development of Data and Models for Deep LearningRuchira Manke, Mohammad Wardat, Foutse Khomh, Hridesh RajanICSE 2025
- What's DAT Smell? Untangling and Weaving the Disjoint Assertion Tangle Test SmellMonil Narang, Hang Du, James A. JonesASE 2025
- MUT: Human-in-the-Loop Unit Test MigrationYi Gao, Xing Hu, Tongtong Xu, Xin Xia et al.ICSE 2024 · 3 citations
