Not logged in.

Contribution Details

Type Conference or Workshop Paper
Scope Discipline-based scholarship
Published in Proceedings Yes
Title To Mock or Not to Mock? An Empirical Study on Mocking Practices
Organization Unit
Authors
  • Davide Spadini
  • Mauricio Aniche
  • Magiel Bruntink
  • Alberto Bacchelli
Presentation Type paper
Item Subtype Original Work
Refereed Yes
Status Published in final form
Language
  • English
ISBN 978-1-5386-1544-7
Page Range 402 - 412
Event Title 2017 IEEE/ACM 14th International Conference on Mining Software Repositories (MSR)
Event Type conference
Event Location Buenos Aires, Argentina
Event Start Date June 20 - 2017
Event End Date June 21 - 2017
Place of Publication USA
Publisher IEEE
Abstract Text 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.
Digital Object Identifier 10.1109/MSR.2017.61
Other Identification Number merlin-id:20239
PDF File Download from ZORA
Export BibTeX
EP3 XML (ZORA)