MockSniffer: Characterizing and Recommending Mocking Decisions for Unit Tests
Hengcheng Zhu, Lili Wei, Ming Wen, Yepang Liu, Shing-Chi Cheung, Qin Sheng, Cui Zhou
摘要
In unit testing, mocking is popularly used to ease test effort, reduce test flakiness, and increase test coverage by replacing the actual dependencies with simple implementations. However, there are no clear criteria to determine which dependencies in a unit test should be mocked. Inappropriate mocking can have undesirable consequences: under-mocking could result in the inability to isolate the class under test (CUT) from its dependencies while over-mocking increases the developers' burden on maintaining the mocked objects and may lead to spurious test failures. According to existing work, various factors can determine whether a dependency should be mocked. As a result, mocking decisions are often difficult to make in practice. Studies on the evolution of mocked objects also showed that developers tend to change their mocking decisions: 17% of the studied mocked objects were introduced sometime after the test scripts were created and another 13% of the originally mocked objects eventually became unmocked. In this work, we are motivated to develop an automated technique to make mocking recommendations to facilitate unit testing. We studied 10,846 test scripts in four actively maintained open-source projects that use mocked objects, aiming to characterize the dependencies that are mocked in unit testing. Based on our observations on mocking practices, we designed and implemented a tool, MockSniffer, to identify and recommend mocks for unit tests. The tool is fully automated and requires only the CUT and its dependencies as input. It leverages machine learning techniques to make mocking recommendations by holistically considering multiple factors that can affect developers' mocking decisions. Our evaluation of MockSniffer on ten open-source projects showed that it outperformed three baseline approaches, and achieved good performance in two potential application scenarios.
问问这篇 Paper
智能体会读完全文。
Lune 把这篇 Paper 索引到了每一个公式,引用它的顶会 Paper 也一样。你提问,回答直接引用原文。
引用它的顶会 Paper3
- Use of Test Doubles in Android Testing: An In-Depth InvestigationMattia Fazzini, Chase Choi, Juan Manuel Copia, Gabriel Lee 等ICSE 2022 · 被引用 19 次
- JavaBench: A Benchmark of Object-Oriented Code Generation for Evaluating Large Language ModelsJialun Cao, Zhiyong Chen, Jiarong Wu, Shing-Chi Cheung 等ASE 2024 · 被引用 9 次
- Understanding and Characterizing Mock Assertions in Unit TestsHengcheng Zhu, Valerio Terragni, Lili Wei, Shing-Chi Cheung 等FSE 2025 · 被引用 1 次
相关 Paper
- An automatic refactoring framework for replacing test-production inheritance by mocking mechanismXiao Wang, Lu Xiao, Tingting Yu, Anne Woepse 等FSE 2021 · 被引用 15 次
- Mock Deep Testing: Toward Separate Development of Data and Models for Deep LearningRuchira Manke, Mohammad Wardat, Foutse Khomh, Hridesh RajanICSE 2025
- Program Sketching by Automatically Generating Mocks from TestsNate F. F. Bragg, Jeffrey S. Foster, Cody Roux, Armando Solar-LezamaCAV 2021 · 被引用 4 次
- Studying Test Annotation Maintenance in the WildDong Jae Kim, Nikolaos Tsantalis, Tse-Hsun Peter Chen, Jinqiu YangICSE 2021 · 被引用 20 次
- UTopia: Automatic Generation of Fuzz Driver using Unit TestsBokdeuk Jeong, Joonun Jang, Hayoon Yi, Jiin Moon 等S&P 2023
