AI
LLMs generate working but unreliable test mocks, study finds
A large-scale benchmark reveals that while AI coding agents excel at producing executable mock objects for unit tests, they often fail to capture the true behavior of the code being tested.
Researchers have found a significant gap between what AI systems can generate and what developers actually need when automating the creation of mock objects for unit testing. A new benchmark study shows that large language models and coding agents have become leading tools for this task—yet their outputs frequently run without error while still failing to faithfully simulate the dependencies they're meant to replace.
The challenge of mock artifact generation#
Mocking is essential to modern software testing: it lets developers test code in isolation by replacing real dependencies with simulated versions. Traditionally, researchers have tackled automation through two main approaches. Capture-and-replay methods depend on recording real-world dependency behavior at runtime, while evolutionary approaches like StubCoder limit generation to fixed sets of available symbols. Large language models offer a third path by generating mocks directly from source code without these constraints, yet until now no comprehensive study had evaluated how well they actually perform.
Study design and scope#
Researchers constructed MockBench, a benchmark of 165 mock artifact generation tasks drawn from production Java and Python codebases. The evaluation covered mock objects, stubs (simplified implementations), and mock assertions (verification statements), with expert-validated reference implementations for each. Six LLMs and three coding agents were tested across metrics including whether the generated code runs, whether it behaves as the real dependency would, and whether it catches bugs through proper verification.
Key findings: Execution vs. fidelity#
The results reveal a troubling disconnect. Coding agents significantly outpaced LLMs at producing executable code—that is, outputs that run without crashing. However, this executability advantage did not consistently translate into better behavior fidelity (accurately mimicking how the real dependency behaves) or superior fault detection (catching bugs in code that uses the mocks). This means tests could pass even though the mocks don't properly simulate the actual code dependencies.
Analysis of 660 failure cases identified ten distinct error types across mock objects, stubs, and assertions. The research highlights how behavioral deviations can remain hidden in passing tests, creating a false sense of security for developers.

