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.
Original language | English |
---|---|
Title of host publication | Proceedings - 2017 IEEE/ACM 14th International Conference on Mining Software Repositories, MSR 2017 |
Place of Publication | Los Alamitos, CA |
Publisher | IEEE |
Pages | 402-412 |
Number of pages | 11 |
ISBN (Electronic) | 978-1-5386-1544-7 |
DOIs | |
Publication status | Published - 2017 |
Event | MSR 2017: 14th International Conference on Mining Software Repositories - Buenos Aires, Argentina Duration: 20 May 2017 → 21 May 2017 Conference number: 14 http://2017.msrconf.org/#/home |
Conference
Conference | MSR 2017 |
---|---|
Abbreviated title | MSR |
Country/Territory | Argentina |
City | Buenos Aires |
Period | 20/05/17 → 21/05/17 |
Internet address |
Keywords
- Testing
- Java
- Databases
- Tools
- Software systems
- Interviews
Fingerprint
Dive into the research topics of 'To Mock or Not To Mock? An Empirical Study on Mocking Practices'. Together they form a unique fingerprint.Datasets
-
ToMockOrNotToMock
Spadini, D. (Creator), Aniche, M. (Creator), Bacchelli, A. (Creator) & Bruntink, M. (Creator), TU Delft - 4TU.ResearchData, 6 Apr 2017
DOI: 10.4121/UUID:FCE8653C-344C-4DCB-97AB-C9C1407AD2F0
Dataset/Software: Dataset