Mock objects for testing java systems
Мок-объекты для тестирования Java-систем
2018-11-05
SCID: 54.1/nfp8p668
Discuss with AI
empirical study of mocksinfrastructure-related dependenciesmock objectstest-production couplingtesting java systems
Figures from the paper
Abstract (AI)
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.
Key Findings
1
Changes in production code commonly force corresponding changes in test code due to mocks
2
Developers frequently mock dependencies that make testing difficult, such as infrastructure-related dependencies
3
Developers report that mocking increases coupling between test code and production code
4
Developers tend not to mock classes that encapsulate domain concepts or business rules
5
Empirical data shows mocks often exist from the first version of a test class and persist throughout its lifetime
6
In a study of three OSS projects and one industrial system, over 2,000 mock usages were manually analyzed to identify practices, rationales, and challenges
7
Maintaining mock behavior compatible with the original class is reported as a key challenge by developers
8
Mock objects are widely used in both open source and proprietary projects, but detailed empirical knowledge about their use is lacking
9
Survey responses from over 100 professionals support the qualitative findings from the manual analysis and developer discussions
Research Object
Mock objects used in testing Java systems
Research Subject
Practitioners' usage patterns, rationales, challenges, evolution over time, and impact on coupling between test and production code when using mock objects
Publication Details
Publication Date
2018-11-05
Journal
Publisher
ISSN
Open access PDF
Access Type
Author Information
Download PDF
Subscribe to digest