Mock objects for testing java systems Why and how developers use them, and how they evolve
TL;DR: The study reveals that the usage of mocks is highly dependent on the responsibility and the architectural concern of the 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.
read more
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.
read more
Chat with Paper
AI Agents for this Paper
Find similar papers on Google Scholar, PubMed and Arxiv
Write a critical review of this paper
Analyze citations of this paper to find unaddressed research gaps
Citations
•Book
Test Driven Development: By Example
Beck
- 01 Nov 2002
TL;DR: Drive development with automated tests, a style of development called “Test-Driven Development” (TDD for short), which aims to dramatically reduce the defect density of code and make the subject of work crystal clear to all involved.
2.2K
Understanding flaky tests: the developer’s perspective
Moritz Eck,Fabio Palomba,Marco Castelluccio,Alberto Bacchelli +3 more
- 12 Aug 2019
TL;DR: The research shows that flakiness is perceived as significant by the vast majority of developers, regardless of their team's size and project's domain, and it can have effects on resource allocation, scheduling, and the perceived reliability of the test suite.
Understanding Flaky Tests: The Developer's Perspective
TL;DR: In this paper, the authors examined the perceptions of software developers about the nature, relevance, and challenges of flakiness and proposed automated solutions to locate as well as fix flaky tests.
The Art Of Unit Testing With Examples In Net
Manuela Herman
- 01 Jan 2016
TL;DR: The art of unit testing with examples in net is available in our book collection an online access to it is set as public so you can download it instantly.Thank you for downloading the art ofunit testing with example in net.
21
References
•Book
Modern Information Retrieval
Ricardo Baeza-Yates,Berthier Ribeiro-Neto +1 more
- 15 May 1999
TL;DR: In this article, the authors present a rigorous and complete textbook for a first course on information retrieval from the computer science (as opposed to a user-centred) perspective, which provides an up-to-date student oriented treatment of the subject.
A Complexity Measure
TL;DR: Several properties of the graph-theoretic complexity are proved which show, for example, that complexity is independent of physical size and complexity depends only on the decision structure of a program.
6K
•Book
A complexity measure
Thomas J. McCabe
- 04 Oct 1993
TL;DR: In this paper, a graph-theoretic complexity measure for managing and controlling program complexity is presented. But the complexity is independent of physical size, and complexity depends only on the decision structure of a program.
5.1K
•Book
Test Driven Development: By Example
Beck
- 01 Nov 2002
TL;DR: Drive development with automated tests, a style of development called “Test-Driven Development” (TDD for short), which aims to dramatically reduce the defect density of code and make the subject of work crystal clear to all involved.
2.2K
Methods of coping with social desirability bias: A review.
TL;DR: In this article, two main modes of coping with social desirability bias are distinguished: self-deception and other deception, and the use of forced-choice items, the randomized response technique, the bogus pipeline, self-administration of the questionnaire, selection of interviewers, and use of proxy subjects.
2.2K
Related Papers (5)
Gustavo Henrique de Mattos Pereira,Andre Hora +1 more
- 01 Sep 2020
Shaikh Mostafa,Xiaoyin Wang +1 more
- 02 Oct 2014
Mattia Fazzini,Alessandra Gorla,Alessandro Orso +2 more
- 21 Dec 2020