• Cite Icon54
  • https://doi.org/10.1007/s10664-018-9663-0Copy DOI Icon

Mock objects for testing java systems

Show More
  • Abstract
  • Highlights & Summary
  • PDF
  • Literature Map
  • References
  • Citations
  • Similar Papers
Abstract

When testing software artifacts that have several dependencies, one has the possibility of either instantiating these dependencies or using mock objects to simulate the dependencies’ expected behavior. Even though recent quantitative studies showed that mock objects are widely used both in open source and proprietary projects, scientific knowledge is still lacking on how and why practitioners use mocks. An empirical understanding of the situations where developers have (and have not) been applying mocks, as well as the impact of such decisions in terms of coupling and software evolution can be used to help practitioners adapt and improve their future usage. To this aim, we study the usage of mock objects in three OSS projects and one industrial system. More specifically, we manually analyze more than 2,000 mock usages. We then discuss our findings with developers from these systems, and identify practices, rationales, and challenges. These results are supported by a structured survey with more than 100 professionals. Finally, we manually analyze how the usage of mock objects in test code evolve over time as well as the impact of their usage on the coupling between test and production code. Our study reveals that the usage of mocks is highly dependent on the responsibility and the architectural concern of the class. Developers report to frequently mock dependencies that make testing difficult (e.g., infrastructure-related dependencies) and to not mock classes that encapsulate domain concepts/rules of the system. Among the key challenges, developers report that maintaining the behavior of the mock compatible with the behavior of original class is hard and that mocking increases the coupling between the test and the production code. Their perceptions are confirmed by our data, as we observed that mocks mostly exist since the very first version of the test class, and that they tend to stay there for its whole lifetime, and that changes in production code often force the test code to also change.

Loading PDF

Similar Papers
  • Conference Article
  • Citations61

To Mock or Not to Mock? An Empirical Study on Mocking Practices

  • May 01, 2017
  • Davide Spadini +3
  • Conference Article
  • Citations7

Comparing Test and Production Code Quality in a Large Commercial Multicore System

  • Aug 01, 2016
  • S Counsell +5
  • Research Article
  • Citations2

Towards automatically identifying the co‐change of production and test code

  • Jan 11, 2024
  • Software Testing, Verification and Reliability
  • Yuan Huang +3
  • Research Article
  • Citations17

Revisiting the Identification of the Co-evolution of Production and Test Code

  • Sep 30, 2023
  • ACM Transactions on Software Engineering and Methodology
  • Weifeng Sun +5
  • Conference Article
  • Citations64

Studying Fine-Grained Co-evolution Patterns of Production and Test Code

  • Sep 01, 2014
  • Cosmin Marsavina +2
  • Conference Article
  • Citations24

Understanding and Facilitating the Co-Evolution of Production and Test Code

  • Mar 01, 2021
  • Sinan Wang +4
  • Research Article

Supporting Quality In Test Code For Higher Quality Software Systems

  • Jan 01, 2021
  • Research Repository (Delft University of Technology)
  • Davide Spadini
  • Research Article

Understanding Self-Admitted Technical Debt in Test Code: An Empirical Study

  • Jan 05, 2026
  • ACM Transactions on Software Engineering and Methodology
  • Ibuki Nakamura +3
  • Conference Article
  • Citations2

Drift: Fine-Grained Prediction of the Co-Evolution of Production and Test Code via Machine Learning

  • Aug 04, 2023
  • Lei Liu +4
  • Research Article
  • Citations178

Studying the co-evolution of production and test code in open source and industrial developer test processes through repository mining

  • Sep 15, 2010
  • Empirical Software Engineering
  • Andy Zaidman +3
  • Conference Article
  • Citations4

Exploring and Improving Code Completion for Test Code

  • Apr 15, 2024
  • Tingwei Zhu +6
  • Research Article
  • Citations13

A comparative study of test code clones and production code clones

  • Mar 08, 2021
  • Journal of Systems and Software
  • Brent Van Bladel +1
  • Research Article

모형 객체 패턴을 이용한 Federation 통합시험 방법

  • Dec 31, 2011
  • Journal of the Korea Society for Simulation
  • Jun-Yong Shim +3
  • Conference Article
  • Citations14

Automated Static Analysis of Unit Test Code

  • Mar 01, 2016
  • Rudolf Ramler +2
  • Conference Article
  • Citations115

An empirical study of bugs in test code

  • Sep 01, 2015
  • Arash Vahabzadeh +2
Cactus Communications logo

Copyright 2026 Cactus Communications. All rights reserved.