Mock objects: a case study in industry


Context: Mock objects are commonly used in unit tests to isolate a class from its dependencies by substituting a dependency class instead of the original. Problem: However, in addition to the use of mock objects in the vast majority of OO applications, there are some discrepancies in their use. Solution: This work aims to present a case study of an industry application regarding the use of mock objects. The application in question is part of a private flight management system. IS Theory: We conceived this work based on the General Systems Theory, specifically to evaluate a microservice-based system's use of testing doubles during testing automation. Method: In the analyzed application, mock object implementations are highly related to the system design. For example, the number of dependencies in a production class is directly related to the number of mocks in the respective test class. As a consequence, poor design choices are harmful to intrinsic quality factors such as the maintainability of the application tests. Our study uses metrics to analyze this practice. The research will consider factors of this system, aiming mainly to contribute to the improvement of test doubles by the test team. Summary of Results: Application of simulated objects in a similar system indicates that developers are making immature use of the technique, possibly due to system design problems. This study concludes that theory and practice are misaligned. Contributions and Impact in the IS area: The main contribution is to indicate points to improving software testing practice by using mocks correctly.
Palavras-chave: Mock Objects, OOP, OO Design, Software Quality


Shyam R Chidamber and Chris F Kemerer. 1994. A metrics suite for object oriented design. IEEE Transactions on software engineering 20, 6 (1994), 476–493.

Eric Evans. 2004. Domain-driven design: tackling complexity in the heart of software. Addison-Wesley, Boston.

Martin Fowler. 2007. Mocks aren't stubs.

Steve Freeman, Tim Mackinnon, Nat Pryce, and Joe Walnes. 2004. Mock roles, not objects. In 19th ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications. ACM, Canada, 236–246.

Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1995. Design patterns: elements of reusable object-oriented software. Addison-Wesley, Reading, Mass.

Pavneet Singh Kochhar, Xin Xia, and David Lo. 2019. Practitioners’ Views on Good Software Testing Practices. In Proceedings of the 41st International Conference on Software Engineering: Software Engineering in Practice(ICSE-SEIP ’19), Vol. 1. IEEE Press, Montreal, Quebec, Canada, 61–70.

Jeff Lagr. 2003. Don't mock me.

Tim Mackinnon, Steve Freeman, and Philip Craig. 2001. Endo-Testing: Unit Testing with Mock Objects. In Extreme Programming Examined. Addison-Wesley Longman Publishing Co., Inc., USA, 287–301.

Madhuri R. Marri, Tao Xie, Nikolai Tillmann, Jonathan de Halleux, and Wolfram Schulte. 2009. An empirical study of testing file-system-dependent software with mock objects. In 2009 ICSE Workshop on Automation of Software Test. IEEE, Canada, 149–153.

Robert Martin. 1994. OO design quality metrics. An analysis of dependencies 12, 1 (1994), 151–170.

Robert C. Martin. 2018. Clean architecture: a craftsman's guide to software structure and design. Prentice Hall, London, England. OCLC: on1004983973.

Gerard Meszaros. 2007. xUnit test patterns: refactoring test code. Addison-Wesley, Upper Saddle River, NJ.

Shaikh Mostafa and Xiaoyin Wang. 2014. An Empirical Study on the Usage of Mocking Frameworks in Software Testing. In 14th International Conference on Quality Software. IEEE, USA, 127–132.

Per Runeson and Martin Höst. 2009. Guidelines for Conducting and Reporting Case Study Research in Software Engineering. Empirical Softw. Engg. 14, 2 (apr 2009), 131–164.

Amjan Shaik. 2012. Object Oriented Software Metrics and Quality Assessment: Current State of the Art. International Journal of Computer Applications 37 (2012), 10.

Davide Spadini, Mauricio Aniche, Magiel Bruntink, and Alberto Bacchelli. 2017. To Mock or Not to Mock? An Empirical Study on Mocking Practices. In 2017 IEEE/ACM 14th International Conference on Mining Software Repositories (MSR). IEEE, Buenos Aires, Argentina, 402–412.

Davide Spadini, Maurício Aniche, Magiel Bruntink, and Alberto Bacchelli. 2019. Mock objects for testing java systems: Why and how developers use them, and how they evolve. Empirical Software Engineering 24, 3 (June 2019), 1461–1498.

Cătălin Tudose. 2020. JUnit in action (third edition ed.). Manning Publications Co, Shelter Island, NY.

C. Wohlin, P. Runeson, M. Höst, M. C. Ohlsson, B. Regnell, and A. Wesslén. 2012. Experimentation in software engineering. Springer Heidelberg, New York, NY, USA.
Como Citar

Selecione um Formato
IBARRA, Camilo Hernán Villota; FARIA, Daniel Lippi Castro De; ENDO, André Takeshi; BEDER, Delano Medeiros; VINCENZI, Auri Marcelo Rizzo. Mock objects: a case study in industry. In: SIMPÓSIO BRASILEIRO DE SISTEMAS DE INFORMAÇÃO (SBSI), 19. , 2023, Maceió/AL. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2023 .