Executable but Unfaithful: Mock Object, Stub, and Assertion Generation by LLMs and Coding Agents
Hao NingJiahui DongZhen YangGuanda YanYichen SunXuanyu ZhuZheng ShenYifei PeiJacky Keung
Jie M. Zhang Hao Ning
Jiahui Dong
Zhen Yang
Guanda Yan
Yichen Sun
Xuanyu Zhu
Zheng Shen
Yifei Pei
Jacky Keung

Jie M. Zhang
+10
MockBench is introduced as a benchmark of 165 mock object, stub, and mock assertion generation tasks drawn from real-world Java and Python projects, with validated reference artifacts, to systematically evaluate whether LLMs and coding agents can generate mocking artifacts from source code without recorded dependency executions or fixed symbol pools. Six LLMs and three coding agents are assessed on executability, behavior fidelity, and interaction-fault detection, alongside comparisons with existing tools and sensitivity analysis. Results show these techniques are state of the art for mock-based testing: coding agents substantially improve executability over LLMs, but these gains do not consistently translate into higher behavior fidelity or better interaction-fault detection. Analysis of 660 failures identifies ten error types across the three artifact categories, revealing behavioral deviations that passing tests can conceal.

arXiv ·
· October 10, 2026