Print Email Facebook Twitter To Mock or Not To Mock? Title To Mock or Not To Mock?: An Empirical Study on Mocking Practices Author Spadini, D. (TU Delft Software Engineering; Software Improvement Group) Aniche, Maurício (TU Delft Software Engineering) Bruntink, Magiel (Software Improvement Group) Bacchelli, A. (TU Delft Software Engineering) Date 2017 Abstract When writing automated unit tests, developers often deal with software artifacts that have several dependencies. In these cases, one has the possibility of either instantiating the dependencies or using mock objects to simulate the dependencies' expected behavior. Even though recent quantitative studies showed that mock objects are widely used in OSS projects, scientific knowledge is still lacking on how and why practitioners use mocks. Such a knowledge is fundamental to guide further research on this widespread practice and inform the design of tools and processes to improve it. The objective of this paper is to increase our understanding of which test dependencies developers (do not) mock and why, as well as what challenges developers face with this practice. To this aim, we create MOCKEXTRACTOR, a tool to mine the usage of mock objects in testing code and employ it to collect data from three OSS projects and one industrial system. Sampling from this data, we manually analyze how more than 2,000 test dependencies are treated. Subsequently, we discuss our findings with developers from these systems, identifying practices, rationales, and challenges. These results are supported by a structured survey with more than 100 professionals. The 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 and prefer 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. Subject TestingJavaDatabasesToolsSoftware systemsInterviews To reference this document use: http://resolver.tudelft.nl/uuid:a0b02521-ad00-4f96-9d96-17a85dc23f99 DOI https://doi.org/10.1109/MSR.2017.61 Publisher IEEE, Los Alamitos, CA ISBN 978-1-5386-1544-7 Source Proceedings - 2017 IEEE/ACM 14th International Conference on Mining Software Repositories, MSR 2017 Event MSR 2017, 2017-05-20 → 2017-05-21, Buenos Aires, Argentina Part of collection Institutional Repository Document type conference paper Rights © 2017 D. Spadini, Maurício Aniche, Magiel Bruntink, A. Bacchelli Files PDF TUD_SERG_2017_016.pdf 418.44 KB Close viewer /islandora/object/uuid:a0b02521-ad00-4f96-9d96-17a85dc23f99/datastream/OBJ/view