Back to search

University of Saskatchewan

Test Mocking in Practice: Developer Challenges and the Impact on Software Maintainability

Abstract

dc:description.abstract

Mocking is a common unit testing technique that is used to simplify tests, reduce flakiness, and improve coverage by replacing real dependencies with simplified implementations. Despite its widespread use in Open Source Software (OSS) projects, there is limited understanding of how and why developers use mocks and the challenges they face. Although extensive research has explored the benefits of mocking for testing, its longterm impact on software maintainability remains underexplored. However, under-mocking risks compromising the isolation of the class under test, while over-mocking introduces excessive maintenance overhead and potential test fragility. In light of these limitations, we present two complementary studies in this thesis. In the first collaborative study, we have analyzed 25,302 questions related to Mocking on Stackoverflow (SO) to identify the challenges faced by developers. We have employed Latent Dirichlet Allocation (LDA) for topic modeling, pyLDAVis for topic visualizations, identified 30 key topics, and constructed a topic hierarchy. Consequently, we analyzed the annual and relative probabilities of each category to understand the evolution of mocking-related discussions. Trend analysis reveals that categories such as Mocking Techniques and External Services have remained consistently dominant, highlighting evolving developer priorities and ongoing technical challenges. Popular topics like Framework Selection tend to have lower difficulty and faster resolution times, while complex topics like HTTP Requests and Responses are more likely to remain unanswered and take longer to resolve. A classification of questions into How, Why, What, and Other revealed that over 70% are How questions, particularly in practical domains like file access and APIs, indicating a strong need for implementation guidance. Why questions are more prevalent in error-handling contexts, reflecting conceptual challenges in debugging, while What questions are rare and mostly tied to theoretical discussions. These insights offer valuable guidance for improving developer support, tooling, and educational content in the context of mocking and unit testing. In the second study, we evaluate the relationship between Mockito usage and method-level maintainability across a large-scale dataset of 50 open-source Java projects. We categorized methods into three groups: Mocked, Unmocked, and Impacted by Mocking. We identified mocked methods based on stubbing patterns commonly outlined in the official documentation of the Mockito framework. A method is categorized as impacted by mocking if it contains within its body any invocation of mocking APIs such as when, given, defaultAnswer, or lenient. Next, we analyzed 18 key software quality metrics, including code quality, cognitive effort, and evaluate maintainability trend over time. Our results reveal that methods impacted by mocking differ significantly from mocked and unmocked methods. Impacted methods tend to be more complex, less readable, and harder to maintain. They exhibit substantially higher cognitive demands compared to both mocked and unmocked methods, indicating increased difficulty in comprehension. These findings suggest that while mocking simplifies the mocked components themselves, it shifts complexity and maintenance burden onto the impacted code. Future studies could replicate our methodology across other programming languages, and explore the impact of alternative mocking frameworks.

Degree

thesis:*
Name thesis:degree_name
Master of Science (M.Sc.)
Level thesis:degree_level
Masters
Discipline thesis:degree_discipline
Computer Science
Department thesis:degree_department
Computer Science
Grantor
University of Saskatchewan
Year dc:date.issued
2025

Author and committee

dc:creator, dc:contributor.*
Author dc:creator
  • Ahmed, Mumtahina
Advisor dc:contributor.advisor
  • Roy, Chanchal
Committee members dc:contributor.committeemember
  • Roy, Banani
  • Yeh, Yen-Ting (Allen)
ORCID person:identifier.orcid

Subjects

dc:subject × 1

Rights

Language dc:language.iso
en

Identifiers

dc:identifier.*
Handle dc:identifier.uri
https://hdl.handle.net/10388/17610

Chain of custody

source
Harvested from
University of Saskatchewan
Base URL
harvest.usask.ca/server/oai/request
Last updated
2026-11-19
Source record
OAI-PMH GetRecord
citation

Ahmed, Mumtahina. Test Mocking in Practice: Developer Challenges and the Impact on Software Maintainability. Masters thesis, University of Saskatchewan, 2025. https://hdl.handle.net/10388/17610